diff --git a/srcs/requirements/game_server/game_back/src/server/class/GameSession.ts b/srcs/requirements/game_server/game_back/src/server/class/GameSession.ts index caedea3f..322b845d 100644 --- a/srcs/requirements/game_server/game_back/src/server/class/GameSession.ts +++ b/srcs/requirements/game_server/game_back/src/server/class/GameSession.ts @@ -233,7 +233,7 @@ export class GameSession { }); const gc = this.components; - await fetch(c.addressBackEnd + "/game/matchEnd", + await fetch(c.addressBackEnd + "/game/gameserver/updategame", { method: "POST", headers: { 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 4d122f8d..16a4f1d5 100644 --- a/srcs/requirements/nestjs/api_back/src/game/game.service.ts +++ b/srcs/requirements/nestjs/api_back/src/game/game.service.ts @@ -1,4 +1,4 @@ -import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; +import { ConsoleLogger, HttpException, HttpStatus, Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { createCipheriv, randomBytes, scrypt } from 'crypto'; import { User } from 'src/users/entities/user.entity'; @@ -31,14 +31,13 @@ export class GameService { .leftJoinAndSelect("user.stats", "stats") .orderBy('stats.winGame', "DESC") .getMany(); - if (!users) - return new HttpException("No ranking for now.", HttpStatus.NOT_FOUND) const partialUser : Partial[] = [] for (const user of users) { if (await this.friendShipService.findIfUserIsBlockedOrHasBlocked(currentUser.id.toString(), user.id.toString()) === false) partialUser.push({username : user.username, stats : user.stats }) } + console.log(...partialUser) return partialUser; } @@ -58,9 +57,10 @@ export class GameService { async generateToken(user : User, grantTicketDto : GrantTicketDto) { - if (user.status === "In Game" || user.status === "In Pool") - return new HttpException("You can't play two games", HttpStatus.FORBIDDEN); - else if (grantTicketDto.isGameIsWithInvitation === true) + console.log(user.status); + // if (user.status === "In Game" || user.status === "In Pool") + // return new HttpException("You can't play two games", HttpStatus.FORBIDDEN); + if (grantTicketDto.isGameIsWithInvitation === true) { const secondUser : Partial = await this.userService.findOneByUsername(user.id.toString(), grantTicketDto.playerTwoUsername) if (!secondUser || secondUser.username === user.username) @@ -236,19 +236,19 @@ export class GameService { if (!game) return HttpStatus.INTERNAL_SERVER_ERROR 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}) return HttpStatus.OK } async updateGame(updateGameDto : UpdateGameDto) { - const game = await this.gameRepository.preload( - {gameServerIdOfTheMatch : updateGameDto.gameServerIdOfTheMatch, - ...updateGameDto} - ) + console.log("Updata game" + updateGameDto) + const game = await this.gameRepository.createQueryBuilder('game') + .where("game.gameServerIdOfTheMatch = :gameServerIdOfTheMatch", {gameServerIdOfTheMatch : updateGameDto.gameServerIdOfTheMatch}) + .getOne(); if (!game) throw new HttpException(`The game could not be updated.`,HttpStatus.NOT_FOUND); game.isMatchIsFinished = true; + game.playerOneUsernameResult = updateGameDto.playerOneUsernameResult + game.playerTwoUsernameResult = updateGameDto.playerTwoUsernameResult this.userRepository.save(game); const playerOne = await this.userRepository.findOneBy({username : game.playerOneUsername}) const playerTwo = await this.userRepository.findOneBy({username : game.playerTwoUsername}) diff --git a/srcs/requirements/svelte/api_front/src/pages/game/Ranking.svelte b/srcs/requirements/svelte/api_front/src/pages/game/Ranking.svelte index 600ba693..5725bb8b 100644 --- a/srcs/requirements/svelte/api_front/src/pages/game/Ranking.svelte +++ b/srcs/requirements/svelte/api_front/src/pages/game/Ranking.svelte @@ -5,7 +5,7 @@ //user's stuff let currentUser; - let allUsers; + let allUsers = []; let idInterval; onMount( async() => { currentUser = await fetch('http://transcendance:8080/api/v2/user') diff --git a/srcs/requirements/svelte/api_front/src/routes/primaryRoutes.js b/srcs/requirements/svelte/api_front/src/routes/primaryRoutes.js index 1987df52..fd7bcf0c 100644 --- a/srcs/requirements/svelte/api_front/src/routes/primaryRoutes.js +++ b/srcs/requirements/svelte/api_front/src/routes/primaryRoutes.js @@ -6,7 +6,7 @@ import UnauthorizedAccessPage from '../pages/UnauthorizedAccessPage.svelte'; import { wrap } from 'svelte-spa-router/wrap' import TestPage from '../pages/TmpTestPage.svelte'; import Game from '../pages/game/Game.svelte'; -import Ranking from '../pages/Ranking.svelte'; +import Ranking from '../pages/game/Ranking.svelte'; import SpectatorMatchList from '../pages/SpectatorMatchList.svelte';