fin du game
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,7 +219,7 @@ export class GameService {
|
|||||||
const playerOne = await this.userRepository.findOneBy({username : game.playerOneUsername})
|
const playerOne = await this.userRepository.findOneBy({username : game.playerOneUsername})
|
||||||
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)
|
if (game.playerOneUsernameResult === game.playerTwoUsernameResult)
|
||||||
{
|
{
|
||||||
this.userService.incrementDraws(playerOne.id)
|
this.userService.incrementDraws(playerOne.id)
|
||||||
@@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user