Dope Ranking

This commit is contained in:
batche
2022-12-22 17:23:22 +01:00
parent 1e1a32bb78
commit 61831da347
4 changed files with 15 additions and 15 deletions

View File

@@ -233,7 +233,7 @@ export class GameSession {
}); });
const gc = this.components; const gc = this.components;
await fetch(c.addressBackEnd + "/game/matchEnd", await fetch(c.addressBackEnd + "/game/gameserver/updategame",
{ {
method: "POST", method: "POST",
headers: { headers: {

View File

@@ -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 { InjectRepository } from '@nestjs/typeorm';
import { createCipheriv, randomBytes, scrypt } from 'crypto'; import { createCipheriv, randomBytes, scrypt } from 'crypto';
import { User } from 'src/users/entities/user.entity'; import { User } from 'src/users/entities/user.entity';
@@ -31,14 +31,13 @@ export class GameService {
.leftJoinAndSelect("user.stats", "stats") .leftJoinAndSelect("user.stats", "stats")
.orderBy('stats.winGame', "DESC") .orderBy('stats.winGame', "DESC")
.getMany(); .getMany();
if (!users)
return new HttpException("No ranking for now.", HttpStatus.NOT_FOUND)
const partialUser : Partial<User>[] = [] const partialUser : Partial<User>[] = []
for (const user of users) for (const user of users)
{ {
if (await this.friendShipService.findIfUserIsBlockedOrHasBlocked(currentUser.id.toString(), user.id.toString()) === false) if (await this.friendShipService.findIfUserIsBlockedOrHasBlocked(currentUser.id.toString(), user.id.toString()) === false)
partialUser.push({username : user.username, stats : user.stats }) partialUser.push({username : user.username, stats : user.stats })
} }
console.log(...partialUser)
return partialUser; return partialUser;
} }
@@ -58,9 +57,10 @@ export class GameService {
async generateToken(user : User, grantTicketDto : GrantTicketDto) async generateToken(user : User, grantTicketDto : GrantTicketDto)
{ {
if (user.status === "In Game" || user.status === "In Pool") console.log(user.status);
return new HttpException("You can't play two games", HttpStatus.FORBIDDEN); // if (user.status === "In Game" || user.status === "In Pool")
else if (grantTicketDto.isGameIsWithInvitation === true) // return new HttpException("You can't play two games", HttpStatus.FORBIDDEN);
if (grantTicketDto.isGameIsWithInvitation === true)
{ {
const secondUser : Partial<User> = await this.userService.findOneByUsername(user.id.toString(), grantTicketDto.playerTwoUsername) const secondUser : Partial<User> = await this.userService.findOneByUsername(user.id.toString(), grantTicketDto.playerTwoUsername)
if (!secondUser || secondUser.username === user.username) if (!secondUser || secondUser.username === user.username)
@@ -236,19 +236,19 @@ export class GameService {
if (!game) if (!game)
return HttpStatus.INTERNAL_SERVER_ERROR return HttpStatus.INTERNAL_SERVER_ERROR
console.log("200 retourné pour la création de partie") 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 return HttpStatus.OK
} }
async updateGame(updateGameDto : UpdateGameDto) { async updateGame(updateGameDto : UpdateGameDto) {
const game = await this.gameRepository.preload( console.log("Updata game" + updateGameDto)
{gameServerIdOfTheMatch : updateGameDto.gameServerIdOfTheMatch, const game = await this.gameRepository.createQueryBuilder('game')
...updateGameDto} .where("game.gameServerIdOfTheMatch = :gameServerIdOfTheMatch", {gameServerIdOfTheMatch : updateGameDto.gameServerIdOfTheMatch})
) .getOne();
if (!game) if (!game)
throw new HttpException(`The game could not be updated.`,HttpStatus.NOT_FOUND); throw new HttpException(`The game could not be updated.`,HttpStatus.NOT_FOUND);
game.isMatchIsFinished = true; game.isMatchIsFinished = true;
game.playerOneUsernameResult = updateGameDto.playerOneUsernameResult
game.playerTwoUsernameResult = updateGameDto.playerTwoUsernameResult
this.userRepository.save(game); this.userRepository.save(game);
const playerOne = await this.userRepository.findOneBy({username : game.playerOneUsername}) const playerOne = await this.userRepository.findOneBy({username : game.playerOneUsername})
const playerTwo = await this.userRepository.findOneBy({username : game.playerTwoUsername}) const playerTwo = await this.userRepository.findOneBy({username : game.playerTwoUsername})

View File

@@ -5,7 +5,7 @@
//user's stuff //user's stuff
let currentUser; let currentUser;
let allUsers; let allUsers = [];
let idInterval; let idInterval;
onMount( async() => { onMount( async() => {
currentUser = await fetch('http://transcendance:8080/api/v2/user') currentUser = await fetch('http://transcendance:8080/api/v2/user')

View File

@@ -6,7 +6,7 @@ import UnauthorizedAccessPage from '../pages/UnauthorizedAccessPage.svelte';
import { wrap } from 'svelte-spa-router/wrap' import { wrap } from 'svelte-spa-router/wrap'
import TestPage from '../pages/TmpTestPage.svelte'; import TestPage from '../pages/TmpTestPage.svelte';
import Game from '../pages/game/Game.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'; import SpectatorMatchList from '../pages/SpectatorMatchList.svelte';