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)
{
// 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')
.andWhere('tokenGame.playerTwoUsername = :playerTwoUsername', {playerTwoUsername : user.username})
.andWhere('tokenGame.token = :token', {token : token})
@@ -201,6 +198,12 @@ export class GameService {
if (!game)
return HttpStatus.INTERNAL_SERVER_ERROR
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
}
@@ -216,7 +219,7 @@ export class GameService {
const playerOne = await this.userRepository.findOneBy({username : game.playerOneUsername})
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);
return new HttpException("Internal Server Error. Impossible to update the database", HttpStatus.INTERNAL_SERVER_ERROR);
if (game.playerOneUsernameResult === game.playerTwoUsernameResult)
{
this.userService.incrementDraws(playerOne.id)
@@ -232,6 +235,10 @@ export class GameService {
this.userService.incrementVictories(playerOne.id)
this.userService.incrementDefeats(playerTwo.id)
}
playerOne.status = "Connected"
playerTwo.status = "Connected"
this.userRepository.save(playerOne)
this.userRepository.save(playerTwo)
return HttpStatus.OK
}
}