diff --git a/srcs/requirements/nestjs/api_back/src/game/game.service.ts b/srcs/requirements/nestjs/api_back/src/game/game.service.ts index 7523230b..e556df75 100644 --- a/srcs/requirements/nestjs/api_back/src/game/game.service.ts +++ b/srcs/requirements/nestjs/api_back/src/game/game.service.ts @@ -64,8 +64,8 @@ export class GameService { if (grantTicketDto.isGameIsWithInvitation === true) { const secondUser : Partial = 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) diff --git a/srcs/requirements/svelte/api_front/src/pages/game/Game.svelte b/srcs/requirements/svelte/api_front/src/pages/game/Game.svelte index 39abb380..7bbef38f 100644 --- a/srcs/requirements/svelte/api_front/src/pages/game/Game.svelte +++ b/srcs/requirements/svelte/api_front/src/pages/game/Game.svelte @@ -39,7 +39,6 @@ .then( x => x.json() ); allUsers = await fetch('http://transcendance:8080/api/v2/user/all') .then( x => x.json() ); - options.playerOneUsername = user.username; })