Dope Ranking
This commit is contained in:
@@ -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<User>[] = []
|
||||
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<User> = 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})
|
||||
|
||||
Reference in New Issue
Block a user