forked from DelxHQ/Xenia-WebServices
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
424c6f4
commit bfd9eb8
Showing
19 changed files
with
370 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/application/commandHandlers/UpdatePlayerCommandHandler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Inject } from '@nestjs/common'; | ||
import { ICommandHandler, CommandHandler } from '@nestjs/cqrs'; | ||
import IPlayerRepository, { | ||
IPlayerRepositorySymbol, | ||
} from 'src/domain/repositories/IPlayerRepository'; | ||
import { UpdatePlayerCommand } from '../commands/UpdatePlayerCommand'; | ||
|
||
@CommandHandler(UpdatePlayerCommand) | ||
export class UpdatePlayerCommandHandler | ||
implements ICommandHandler<UpdatePlayerCommand> | ||
{ | ||
constructor( | ||
@Inject(IPlayerRepositorySymbol) | ||
private repository: IPlayerRepository, | ||
) {} | ||
|
||
async execute(command: UpdatePlayerCommand) { | ||
const player = await this.repository.findByXuid(command.xuid); | ||
|
||
if (!player) { | ||
return undefined; | ||
} | ||
|
||
player.updatePlayer(command.player); | ||
await this.repository.save(player); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Player from 'src/domain/aggregates/Player'; | ||
import Xuid from 'src/domain/value-objects/Xuid'; | ||
|
||
export class UpdatePlayerCommand { | ||
constructor( | ||
public readonly xuid: Xuid, | ||
public readonly player: Player, | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Xuid from 'src/domain/value-objects/Xuid'; | ||
|
||
export class GetPlayersQuery { | ||
constructor(public readonly xuids: Array<Xuid>) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Inject } from '@nestjs/common'; | ||
import { QueryHandler, IQueryHandler } from '@nestjs/cqrs'; | ||
import IPlayerRepository, { | ||
IPlayerRepositorySymbol, | ||
} from 'src/domain/repositories/IPlayerRepository'; | ||
import { GetPlayersQuery } from '../queries/GetPlayersQuery'; | ||
|
||
@QueryHandler(GetPlayersQuery) | ||
export class GetPlayersQueryHandler implements IQueryHandler<GetPlayersQuery> { | ||
constructor( | ||
@Inject(IPlayerRepositorySymbol) | ||
private repository: IPlayerRepository, | ||
) {} | ||
|
||
async execute(query: GetPlayersQuery) { | ||
return this.repository.findByXuids(query.xuids); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { TinyTypeOf } from 'tiny-types'; | ||
|
||
export enum StateFlags { | ||
NONE = 0x0, | ||
ONLINE = 0x1, | ||
PLAYING = 0x2, | ||
VOICE = 0x8, | ||
JOINABLE = 1 << 4, | ||
FRIENDS_ONLY = 1 << 8, | ||
} | ||
|
||
export default class StateFlag extends TinyTypeOf<number>() { | ||
public constructor(value: number) { | ||
super(Number(value)); | ||
} | ||
|
||
private isFlagSet(flag: number) { | ||
return (this.value & flag) == flag; | ||
} | ||
|
||
public isOnline(): boolean { | ||
return this.isFlagSet(StateFlags.ONLINE); | ||
} | ||
|
||
public isJoinable(): boolean { | ||
return this.isFlagSet(StateFlags.JOINABLE); | ||
} | ||
|
||
public isPlaying(): boolean { | ||
return this.isFlagSet(StateFlags.PLAYING); | ||
} | ||
|
||
public setOnline() { | ||
this.value = this.value | StateFlags.ONLINE; | ||
} | ||
|
||
public setJoinable() { | ||
this.value = this.value | StateFlags.JOINABLE; | ||
} | ||
|
||
public setPlaying() { | ||
this.value = this.value | StateFlags.PLAYING; | ||
} | ||
|
||
public toString(): string { | ||
return this.value.toString(16).toUpperCase(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.