Fix : set current_turn to string
This commit is contained in:
@@ -20,6 +20,7 @@ import { GamePipe } from '../pipe/game.pipe';
|
||||
import { ReadUserDto } from '../dto/read-games.dto';
|
||||
import { Observable, fromEvent, map } from 'rxjs';
|
||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||
import { GameService } from '../services/games.service';
|
||||
|
||||
function getPlayer(session: Record<string, any>, game: Game) {
|
||||
const user = session.user as ReadUserDto;
|
||||
@@ -44,6 +45,7 @@ function getPlayer(session: Record<string, any>, game: Game) {
|
||||
export class GamesController {
|
||||
constructor(
|
||||
private readonly lobbyService: LobbyService,
|
||||
private readonly gameService: GameService,
|
||||
private eventEmitter: EventEmitter2,
|
||||
) {}
|
||||
|
||||
@@ -66,6 +68,30 @@ export class GamesController {
|
||||
await this.lobbyService.changeStartingDeck(startingDeckDto, player, game);
|
||||
}
|
||||
|
||||
@Post('endTurn')
|
||||
@UseGuards(AuthGuard)
|
||||
async endTurn(
|
||||
@Param('id') id: string,
|
||||
@Param('id', GamePipe) game: Document<Game> & Game,
|
||||
@Session() session: Record<string, string>,
|
||||
) {
|
||||
const player = getPlayer(session, game);
|
||||
const currentTurn = game.teams.find(
|
||||
(t) => t._id.toHexString() == game.currentTurn,
|
||||
);
|
||||
if (
|
||||
!currentTurn.players.some(
|
||||
(p) => p._id.toHexString() == player._id.toHexString(),
|
||||
)
|
||||
) {
|
||||
throw new HttpException(
|
||||
'It is not your turn to play',
|
||||
HttpStatus.FORBIDDEN,
|
||||
);
|
||||
}
|
||||
await this.gameService.endTurn(game);
|
||||
}
|
||||
|
||||
@Sse('/subscribe')
|
||||
subscribe(
|
||||
@Param('id') id: string,
|
||||
|
||||
Reference in New Issue
Block a user