bugfix generateToken() for invitation
This commit is contained in:
@@ -94,9 +94,15 @@ export class GameService {
|
|||||||
}
|
}
|
||||||
if (grantTicketDto.isGameIsWithInvitation === true)
|
if (grantTicketDto.isGameIsWithInvitation === true)
|
||||||
{
|
{
|
||||||
const secondUser : Partial<User> = await this.userService.findOne(grantTicketDto.playerTwoUsername)
|
if (grantTicketDto.playerTwoUsername === user.username) {
|
||||||
if (!secondUser || secondUser.username === user.username)
|
return res.status(HttpStatus.BAD_REQUEST).json({message : "You cant play against yourself."});
|
||||||
return res.status(HttpStatus.NOT_FOUND).json({message : "User not found OR you want to play with 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 + '_'
|
const encryptedTextToReturn = await this.encryptToken(user.username + '_' + secondUser.username + '_'
|
||||||
+ grantTicketDto.gameOptions + '_' + grantTicketDto.isGameIsWithInvitation + '_' + new Date())
|
+ grantTicketDto.gameOptions + '_' + grantTicketDto.isGameIsWithInvitation + '_' + new Date())
|
||||||
const tok = this.tokenGameRepository.create(grantTicketDto);
|
const tok = this.tokenGameRepository.create(grantTicketDto);
|
||||||
@@ -108,7 +114,6 @@ export class GameService {
|
|||||||
this.userService.updateStatus(secondUser.id, STATUS.IN_POOL)
|
this.userService.updateStatus(secondUser.id, STATUS.IN_POOL)
|
||||||
return res.status(HttpStatus.OK).json({ token : encryptedTextToReturn });
|
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) {
|
else if (grantTicketDto.isGameIsWithInvitation === false) {
|
||||||
const encryptedTextToReturn = await this.encryptToken(user.username + '_'
|
const encryptedTextToReturn = await this.encryptToken(user.username + '_'
|
||||||
+ grantTicketDto.gameOptions + '_' + grantTicketDto.isGameIsWithInvitation + '_' + new Date())
|
+ grantTicketDto.gameOptions + '_' + grantTicketDto.isGameIsWithInvitation + '_' + new Date())
|
||||||
@@ -285,9 +290,9 @@ export class GameService {
|
|||||||
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);
|
||||||
this.userService.updateStatus(playerOne.id, STATUS.CONNECTED)
|
this.userService.updateStatus(playerOne.id, STATUS.CONNECTED);
|
||||||
this.userService.updateStatus(playerTwo.id, STATUS.CONNECTED)
|
this.userService.updateStatus(playerTwo.id, STATUS.CONNECTED);
|
||||||
if (game.playerOneUsernameResult === game.playerTwoUsernameResult)
|
if (game.playerOneUsernameResult === game.playerTwoUsernameResult)
|
||||||
{
|
{
|
||||||
this.userService.incrementDraws(playerOne.id)
|
this.userService.incrementDraws(playerOne.id)
|
||||||
this.userService.incrementDraws(playerTwo.id)
|
this.userService.incrementDraws(playerTwo.id)
|
||||||
|
|||||||
Reference in New Issue
Block a user