correction de bugs mineurs

This commit is contained in:
batche
2022-12-22 15:41:29 +01:00
parent 9586fe63fc
commit dca3df1bde
2 changed files with 11 additions and 4 deletions

View File

@@ -64,8 +64,8 @@ export class GameService {
if (grantTicketDto.isGameIsWithInvitation === true)
{
const secondUser : Partial<User> = await this.userService.findOneByUsername(user.id.toString(), grantTicketDto.playerTwoUsername)
if (!secondUser)
return new HttpException("The requested second player does not exist", HttpStatus.NOT_FOUND);
if (!secondUser || secondUser.username === user.username)
return new HttpException("The requested second player does not exist OR you want to play against yourself. :P", HttpStatus.NOT_FOUND);
const encryptedTextToReturn = await this.encryptToken(user.username + '_' + secondUser.username + '_'
+ grantTicketDto.gameOptions + '_' + grantTicketDto.isGameIsWithInvitation + '_' + new Date())
const tok = this.tokenGameRepository.create(grantTicketDto);
@@ -185,8 +185,16 @@ export class GameService {
.where('tokengame.token = :token', {token : token})
.getOne();
if (tokenGame)
{
const playerOne = await this.userRepository.findOneBy({username : tokenGame.playerOneUsername})
const playerTwo = await this.userRepository.findOneBy({username : tokenGame.playerTwoUsername})
playerOne.status = "Connected"
playerTwo.status = "Connected"
this.userRepository.save(playerOne)
this.userRepository.save(playerTwo)
return this.tokenGameRepository.remove(tokenGame);
return new HttpException("Invitation not found !", HttpStatus.NOT_FOUND)
}
return new HttpException("Token not found !", HttpStatus.NOT_FOUND)
}
async acceptInvitation(user : User, token : string)