Si un défi était en cours lors d'une capture, on le clôt
This commit is contained in:
		| @@ -39,6 +39,7 @@ export class GameController { | ||||
|    * Change de joueur⋅se en course après une capture | ||||
|    *  | ||||
|    * @throws {401} Non authentifié⋅e | ||||
|    * @throws {409} La partie n'est pas démarrée | ||||
|    */ | ||||
|   @Post('/switch-running-player') | ||||
|   @UseGuards(JwtAuthGuard) | ||||
|   | ||||
| @@ -50,6 +50,22 @@ export class GameService { | ||||
|  | ||||
|   async switchRunningPlayer(): Promise<Game> { | ||||
|     const game = await this.find() | ||||
|     if (!game.started) | ||||
|       throw new ConflictException("La partie n'a pas encore démarré.") | ||||
|  | ||||
|     // Clôture de l'éventuel défi en cours, qui n'a alors pas été réussi | ||||
|     await this.prisma.challengeAction.updateMany({ | ||||
|       where: { | ||||
|         playerId: game.currentRun.runnerId, | ||||
|         runId: game.currentRunId, | ||||
|         active: true, | ||||
|       }, | ||||
|       data: { | ||||
|         active: false, | ||||
|         success: false, | ||||
|       }, | ||||
|     }) | ||||
|  | ||||
|     const newRunnerId = game.currentRun.runnerId == 1 ? 2 : 1 | ||||
|     const firstRun = await this.prisma.playerRun.findFirst({ where: { runnerId: newRunnerId } }) !== null | ||||
|     const newRun = await this.prisma.playerRun.create({ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user