Feat : additional checks to endTurn
This commit is contained in:
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user