Ajout endpoint pour changer de joueur⋅se actif⋅ve
This commit is contained in:
parent
4c157ff67f
commit
3eea3a7409
@ -35,6 +35,18 @@ export class GameController {
|
||||
return new GameEntity(await this.gameService.start())
|
||||
}
|
||||
|
||||
/**
|
||||
* Change de joueur⋅se 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.
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user