From 224bd71a2ce2432f5de60c9a749327a473ea6251 Mon Sep 17 00:00:00 2001 From: Legonzaur Date: Thu, 13 Jun 2024 22:40:27 -0400 Subject: [PATCH] Feat : additional checks to endTurn --- src/games/controllers/games.controller.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/games/controllers/games.controller.ts b/src/games/controllers/games.controller.ts index 96fbd6f..19f6221 100644 --- a/src/games/controllers/games.controller.ts +++ b/src/games/controllers/games.controller.ts @@ -75,10 +75,16 @@ export class GamesController { @Param('id', GamePipe) game: Document & Game, @Session() session: Record, ) { + if (!game.started || !game.currentTurn) { + throw new HttpException('Game not started', HttpStatus.BAD_REQUEST); + } const player = getPlayer(session, game); const currentTurn = game.teams.find( (t) => t._id.toHexString() == game.currentTurn, ); + if (!currentTurn.players.some((p) => p._id == player._id)) { + throw new HttpException('It is not your turn', HttpStatus.BAD_REQUEST); + } if ( !currentTurn.players.some( (p) => p._id.toHexString() == player._id.toHexString(),