fin du game

This commit is contained in:
batche
2022-12-21 16:38:34 +01:00
parent cc797d1118
commit e786324896

View File

@@ -161,9 +161,6 @@ export class GameService {
async acceptInvitation(user : User, token : string) async acceptInvitation(user : User, token : string)
{ {
// if (user.status === "In Game")
// return new HttpException("You must finish your game before accept.", HttpStatus.FORBIDDEN)
console.log("On accepte l'invitation")
const tokenGame = await this.tokenGameRepository.createQueryBuilder('tokenGame') const tokenGame = await this.tokenGameRepository.createQueryBuilder('tokenGame')
.andWhere('tokenGame.playerTwoUsername = :playerTwoUsername', {playerTwoUsername : user.username}) .andWhere('tokenGame.playerTwoUsername = :playerTwoUsername', {playerTwoUsername : user.username})
.andWhere('tokenGame.token = :token', {token : token}) .andWhere('tokenGame.token = :token', {token : token})
@@ -201,6 +198,12 @@ export class GameService {
if (!game) if (!game)
return HttpStatus.INTERNAL_SERVER_ERROR return HttpStatus.INTERNAL_SERVER_ERROR
console.log("200 retourné pour la création de partie") console.log("200 retourné pour la création de partie")
const playerOne = await this.userRepository.findOneBy({username : game.playerOneUsername})
const playerTwo = await this.userRepository.findOneBy({username : game.playerTwoUsername})
playerOne.status = "In Game"
playerTwo.status = "In Game"
this.userRepository.save(playerOne)
this.userRepository.save(playerTwo)
return HttpStatus.OK return HttpStatus.OK
} }
@@ -232,6 +235,10 @@ export class GameService {
this.userService.incrementVictories(playerOne.id) this.userService.incrementVictories(playerOne.id)
this.userService.incrementDefeats(playerTwo.id) this.userService.incrementDefeats(playerTwo.id)
} }
playerOne.status = "Connected"
playerTwo.status = "Connected"
this.userRepository.save(playerOne)
this.userRepository.save(playerTwo)
return HttpStatus.OK return HttpStatus.OK
} }
} }