Compare commits

..

2 Commits

4 changed files with 32 additions and 1 deletions

View File

@ -94,7 +94,7 @@ export class ChallengesController {
*
* @throws {401} Non authentifiée
* @throws {404} Plus aucun défi n'est disponible
* @throws {409} Un défi est déjà en cours d'accomplissement
* @throws {409} Un défi est déjà en cours d'accomplissement, ou bien vous n'êtes pas en course
*/
@Post('/draw-random')
@UseGuards(JwtAuthGuard)

View File

@ -61,6 +61,9 @@ export class ChallengesService {
}
async drawRandom(player: Player): Promise<ChallengeEntity> {
const game = await this.prisma.game.findUnique({ where: { id: 1 } })
if (game.currentRunnerId != player.id)
throw new ConflictException("Vous n'êtes pas en course, ce n'est pas à vous de tirer un défi.")
const currentChallengeAction = await this.prisma.challengeAction.findFirst({
where: {
playerId: player.id,

View File

@ -35,6 +35,18 @@ export class GameController {
return new GameEntity(await this.gameService.start())
}
/**
* Change de joueurse en course après une capture
*
* @throws {401} Non authentifiée
*/
@Post('/switch-running-player')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
async switchRunningPlayer(): Promise<GameEntity> {
return new GameEntity(await this.gameService.switchRunningPlayer())
}
/**
* Arrêter le jeu
* @remarks Arrête le jeu (si déjà lancé), à n'utiliser qu'en fin de partie.

View File

@ -38,6 +38,22 @@ export class GameService {
})
}
async switchRunningPlayer(): Promise<Game> {
const game = await this.find()
const newRunnerId = game.currentRunnerId == 1 ? 2 : 1
await this.prisma.moneyUpdate.create({
data: {
playerId: newRunnerId,
amount: 300,
reason: MoneyUpdateType.START,
}
})
return await this.prisma.game.update({
where: { id: game.id },
data: { currentRunnerId: newRunnerId },
})
}
async stop(): Promise<Game> {
const game = await this.find()
if (!game.started)