From 3eea3a740971656a648312a674e96fdd8876d9cc Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Sun, 8 Dec 2024 20:01:43 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20endpoint=20pour=20changer=20de=20joueur?= =?UTF-8?q?=E2=8B=85se=20actif=E2=8B=85ve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/game/game.controller.ts | 12 ++++++++++++ server/src/game/game.service.ts | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/server/src/game/game.controller.ts b/server/src/game/game.controller.ts index e4e2ad7..d384a9e 100644 --- a/server/src/game/game.controller.ts +++ b/server/src/game/game.controller.ts @@ -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 { + 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. diff --git a/server/src/game/game.service.ts b/server/src/game/game.service.ts index f23fae7..3b0290a 100644 --- a/server/src/game/game.service.ts +++ b/server/src/game/game.service.ts @@ -38,6 +38,22 @@ export class GameService { }) } + async switchRunningPlayer(): Promise { + 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 { const game = await this.find() if (!game.started)