mini changement sur la façon de mettre à jour le statut pendant la création d'une partie. Cette corection sera complétée par une correction au niveau du gameserver

This commit is contained in:
cherif
2023-01-13 14:49:06 +01:00
parent 97f0a52b2c
commit 0addb48c84

View File

@@ -92,7 +92,6 @@ export class GameService {
} }
this.userRepository.save(user); this.userRepository.save(user);
} }
// if (grantTicketDto.isGameIsWithInvitation === true && user.status !== STATUS.IN_GAME) // WIP: need to fix STATUS.IN_GAME
if (grantTicketDto.isGameIsWithInvitation === true) if (grantTicketDto.isGameIsWithInvitation === true)
{ {
const secondUser : Partial<User> = await this.userService.findOne(grantTicketDto.playerTwoUsername) const secondUser : Partial<User> = await this.userService.findOne(grantTicketDto.playerTwoUsername)
@@ -106,6 +105,7 @@ export class GameService {
tok.token = encryptedTextToReturn; tok.token = encryptedTextToReturn;
this.tokenGameRepository.save(tok); this.tokenGameRepository.save(tok);
this.userService.updateStatus(user.id, STATUS.IN_POOL) this.userService.updateStatus(user.id, STATUS.IN_POOL)
this.userService.updateStatus(secondUser.id, STATUS.IN_POOL)
return res.status(HttpStatus.OK).json({ token : encryptedTextToReturn }); 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 // 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') const userOne : User = await this.userRepository.createQueryBuilder('user')
.where("user.username = :username", {username : tokenGame.playerOneUsername}) .where("user.username = :username", {username : tokenGame.playerOneUsername})
.getOne(); .getOne();
this.userService.updateStatus(userOne.id, STATUS.IN_GAME)
const userTwo : User = await this.userRepository.createQueryBuilder('user') const userTwo : User = await this.userRepository.createQueryBuilder('user')
.where("user.username = :username", {username : tokenGame.playerTwoUsername}) .where("user.username = :username", {username : tokenGame.playerTwoUsername})
.getOne(); .getOne();
this.deleteToken(userOne) this.deleteToken(userOne)
this.deleteToken(userTwo) this.deleteToken(userTwo)
this.userService.updateStatus(userTwo.id, STATUS.IN_GAME)
} }
return true; return true;
} }
@@ -168,7 +166,6 @@ export class GameService {
const user : User = await this.userRepository.createQueryBuilder('user') const user : User = await this.userRepository.createQueryBuilder('user')
.where("user.username = :username", {username : tokenGame.playerOneUsername}) .where("user.username = :username", {username : tokenGame.playerOneUsername})
.getOne(); .getOne();
this.userService.updateStatus(user.id, STATUS.IN_GAME)
this.deleteToken(user) this.deleteToken(user)
return true; return true;
} }
@@ -259,6 +256,14 @@ export class GameService {
this.gameRepository.save(game); this.gameRepository.save(game);
if (!game) if (!game)
return HttpStatus.INTERNAL_SERVER_ERROR 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") console.log("200 retourné pour la création de partie")
return HttpStatus.OK return HttpStatus.OK
} }
@@ -280,7 +285,9 @@ export class GameService {
const playerTwo = await this.userRepository.findOneBy({username : game.playerTwoUsername}) const playerTwo = await this.userRepository.findOneBy({username : game.playerTwoUsername})
if (!playerOne || !playerTwo) if (!playerOne || !playerTwo)
return new HttpException("Internal Server Error. Impossible to update the database", HttpStatus.INTERNAL_SERVER_ERROR); 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(playerOne.id)
this.userService.incrementDraws(playerTwo.id) this.userService.incrementDraws(playerTwo.id)
@@ -296,8 +303,6 @@ export class GameService {
this.userService.incrementVictories(playerOne.id) this.userService.incrementVictories(playerOne.id)
this.userService.incrementDefeats(playerTwo.id) this.userService.incrementDefeats(playerTwo.id)
} }
this.userService.updateStatus(playerOne.id, STATUS.CONNECTED)
this.userService.updateStatus(playerTwo.id, STATUS.CONNECTED)
return HttpStatus.OK return HttpStatus.OK
} }
} }