Feat : additional checks to endTurn

This commit is contained in:
2024-06-13 22:40:27 -04:00
parent a19a7efc93
commit 224bd71a2c
@@ -75,10 +75,16 @@ export class GamesController {
@Param('id', GamePipe) game: Document<Game> & Game,
@Session() session: Record<string, string>,
) {
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(),