bugfix generateToken() for invitation

This commit is contained in:
LuckyLaszlo
2023-01-14 18:34:03 +01:00
parent c9f71d4efb
commit 52f48ae305

View File

@@ -94,9 +94,15 @@ export class GameService {
}
if (grantTicketDto.isGameIsWithInvitation === true)
{
const secondUser : Partial<User> = await this.userService.findOne(grantTicketDto.playerTwoUsername)
if (!secondUser || secondUser.username === user.username)
return res.status(HttpStatus.NOT_FOUND).json({message : "User not found OR you want to play with yourself."});
if (grantTicketDto.playerTwoUsername === user.username) {
return res.status(HttpStatus.BAD_REQUEST).json({message : "You cant play against yourself."});
}
const secondUser : User = await this.userRepository.createQueryBuilder('user')
.where("user.username = :username", {username : grantTicketDto.playerTwoUsername})
.getOne();
if (!secondUser) {
return res.status(HttpStatus.NOT_FOUND).json({message : "Invited user not found"});
}
const encryptedTextToReturn = await this.encryptToken(user.username + '_' + secondUser.username + '_'
+ grantTicketDto.gameOptions + '_' + grantTicketDto.isGameIsWithInvitation + '_' + new Date())
const tok = this.tokenGameRepository.create(grantTicketDto);
@@ -108,7 +114,6 @@ export class GameService {
this.userService.updateStatus(secondUser.id, STATUS.IN_POOL)
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) {
const encryptedTextToReturn = await this.encryptToken(user.username + '_'
+ grantTicketDto.gameOptions + '_' + grantTicketDto.isGameIsWithInvitation + '_' + new Date())
@@ -285,9 +290,9 @@ export class GameService {
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);
this.userService.updateStatus(playerOne.id, STATUS.CONNECTED)
this.userService.updateStatus(playerTwo.id, STATUS.CONNECTED)
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(playerTwo.id)