game workflow corrected
This commit is contained in:
@@ -385,19 +385,16 @@ export class GameRepository implements IGameRepository {
|
||||
}
|
||||
}
|
||||
|
||||
async updateGameState(gameId: string, started: boolean, finished?: boolean, winner?: string): Promise<GameAggregate | null> {
|
||||
async updateGameState(gameId: string, state: GameState, winner?: string): Promise<GameAggregate | null> {
|
||||
const startTime = performance.now();
|
||||
try {
|
||||
const updateData: Partial<GameAggregate> = { started };
|
||||
const updateData: Partial<GameAggregate> = { state };
|
||||
|
||||
if (started && !finished) {
|
||||
updateData.state = GameState.ACTIVE;
|
||||
if (state === GameState.ACTIVE) {
|
||||
updateData.startdate = new Date();
|
||||
}
|
||||
|
||||
if (finished) {
|
||||
updateData.finished = true;
|
||||
updateData.state = GameState.FINISHED;
|
||||
if (state === GameState.FINISHED) {
|
||||
updateData.enddate = new Date();
|
||||
if (winner) {
|
||||
updateData.winner = winner;
|
||||
@@ -407,7 +404,7 @@ export class GameRepository implements IGameRepository {
|
||||
const result = await this.update(gameId, updateData);
|
||||
|
||||
const endTime = performance.now();
|
||||
logDatabase('Game state updated', `executionTime: ${Math.round(endTime - startTime)}ms, gameId: ${gameId}, started: ${started}, finished: ${finished}, winner: ${winner}`);
|
||||
logDatabase('Game state updated', `executionTime: ${Math.round(endTime - startTime)}ms, gameId: ${gameId}, state: ${updateData.state}, winner: ${winner}`);
|
||||
return result;
|
||||
} catch (error) {
|
||||
const endTime = performance.now();
|
||||
|
||||
Reference in New Issue
Block a user