From 0addb48c8470de3e17a6e2b8c0ecf195105f4c10 Mon Sep 17 00:00:00 2001 From: cherif Date: Fri, 13 Jan 2023 14:49:06 +0100 Subject: [PATCH] =?UTF-8?q?mini=20changement=20sur=20la=20fa=C3=A7on=20de?= =?UTF-8?q?=20mettre=20=C3=A0=20jour=20le=20statut=20pendant=20la=20cr?= =?UTF-8?q?=C3=A9ation=20d'une=20partie.=20Cette=20corection=20sera=20comp?= =?UTF-8?q?l=C3=A9t=C3=A9e=20par=20une=20correction=20au=20niveau=20du=20g?= =?UTF-8?q?ameserver?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nestjs/api_back/src/game/game.service.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/srcs/requirements/nestjs/api_back/src/game/game.service.ts b/srcs/requirements/nestjs/api_back/src/game/game.service.ts index a6f7cd02..8c3ff964 100644 --- a/srcs/requirements/nestjs/api_back/src/game/game.service.ts +++ b/srcs/requirements/nestjs/api_back/src/game/game.service.ts @@ -92,7 +92,6 @@ export class GameService { } this.userRepository.save(user); } - // if (grantTicketDto.isGameIsWithInvitation === true && user.status !== STATUS.IN_GAME) // WIP: need to fix STATUS.IN_GAME if (grantTicketDto.isGameIsWithInvitation === true) { const secondUser : Partial = await this.userService.findOne(grantTicketDto.playerTwoUsername) @@ -106,6 +105,7 @@ export class GameService { tok.token = encryptedTextToReturn; this.tokenGameRepository.save(tok); this.userService.updateStatus(user.id, STATUS.IN_POOL) + this.userService.updateStatus(secondUser.id, STATUS.IN_POOL) return res.status(HttpStatus.OK).json({ token : encryptedTextToReturn }); } // else if (grantTicketDto.isGameIsWithInvitation === false && user.status !== STATUS.IN_GAME) { // WIP: need to fix STATUS.IN_GAME @@ -142,13 +142,11 @@ export class GameService { const userOne : User = await this.userRepository.createQueryBuilder('user') .where("user.username = :username", {username : tokenGame.playerOneUsername}) .getOne(); - this.userService.updateStatus(userOne.id, STATUS.IN_GAME) const userTwo : User = await this.userRepository.createQueryBuilder('user') .where("user.username = :username", {username : tokenGame.playerTwoUsername}) .getOne(); this.deleteToken(userOne) this.deleteToken(userTwo) - this.userService.updateStatus(userTwo.id, STATUS.IN_GAME) } return true; } @@ -168,7 +166,6 @@ export class GameService { const user : User = await this.userRepository.createQueryBuilder('user') .where("user.username = :username", {username : tokenGame.playerOneUsername}) .getOne(); - this.userService.updateStatus(user.id, STATUS.IN_GAME) this.deleteToken(user) return true; } @@ -259,6 +256,14 @@ export class GameService { this.gameRepository.save(game); if (!game) return HttpStatus.INTERNAL_SERVER_ERROR + const playerOne : User = await this.userRepository.createQueryBuilder('user') + .where("user.username = :username", {username : creategameDto.playerOneUsername}) + .getOne(); + const playerTwo : User = await this.userRepository.createQueryBuilder('user') + .where("user.username = :username", {username : creategameDto.playerTwoUsername}) + .getOne(); + this.userService.updateStatus(playerOne.id, STATUS.IN_GAME) + this.userService.updateStatus(playerTwo.id, STATUS.IN_GAME) console.log("200 retourné pour la création de partie") return HttpStatus.OK } @@ -280,7 +285,9 @@ export class GameService { const playerTwo = await this.userRepository.findOneBy({username : game.playerTwoUsername}) if (!playerOne || !playerTwo) return new HttpException("Internal Server Error. Impossible to update the database", HttpStatus.INTERNAL_SERVER_ERROR); - if (game.playerOneUsernameResult === game.playerTwoUsernameResult) + this.userService.updateStatus(playerOne.id, STATUS.CONNECTED) + this.userService.updateStatus(playerTwo.id, STATUS.CONNECTED) + if (game.playerOneUsernameResult === game.playerTwoUsernameResult) { this.userService.incrementDraws(playerOne.id) this.userService.incrementDraws(playerTwo.id) @@ -296,8 +303,6 @@ export class GameService { this.userService.incrementVictories(playerOne.id) this.userService.incrementDefeats(playerTwo.id) } - this.userService.updateStatus(playerOne.id, STATUS.CONNECTED) - this.userService.updateStatus(playerTwo.id, STATUS.CONNECTED) return HttpStatus.OK } }