history
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Body, Controller, Get, HttpException, HttpStatus, Param, Post, Req, Res, UseGuards } from '@nestjs/common';
|
||||
import { Body, Controller, Get, HttpException, HttpStatus, Param, Post, Query, Req, Res, UseGuards } from '@nestjs/common';
|
||||
import { AuthenticateGuard, TwoFactorGuard } from 'src/auth/42/guards/42guards';
|
||||
import { User } from 'src/users/entities/user.entity';
|
||||
import { Response } from 'express';
|
||||
@@ -21,11 +21,13 @@ export class GameController {
|
||||
return this.gameService.getMatchesForSpectator();
|
||||
}
|
||||
|
||||
@Get('match/history/:username')
|
||||
@Get('match/history')
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
async getMatchHistory(@Req() req, @Param('username') username: string, @Res() res)
|
||||
async getMatchHistory(@Req() req, @Query('username') username: string, @Res() res)
|
||||
{
|
||||
console.log("DANS MATCH HISTORY")
|
||||
console.log("usrrnmae" + username)
|
||||
return this.gameService.getMatchHistory(username, res);
|
||||
}
|
||||
|
||||
|
||||
@@ -49,22 +49,30 @@ export class GameService {
|
||||
|
||||
async getMatchHistory(username : string, @Res() res : Response)
|
||||
{
|
||||
const user = await this.userService.findOne(username);
|
||||
const user = await this.userRepository.createQueryBuilder("user")
|
||||
.where('user.username = :username', {username: username})
|
||||
.getOne();
|
||||
if (!user)
|
||||
return res.status(HttpStatus.NOT_FOUND).json({message : "History for " + username + " not found"});
|
||||
const gameHistory = await this.matchHistory
|
||||
.createQueryBuilder('history')
|
||||
console.log(user.username + 'OK USERNAME')
|
||||
const gameHistory = await this.matchHistory.
|
||||
createQueryBuilder('history')
|
||||
.leftJoinAndSelect('history.playerOne', 'playerOne')
|
||||
.leftJoinAndSelect('history.playerTwo', 'playerTwo')
|
||||
.where('playerOne.id = :playerOneId', { playerOneId: user.id })
|
||||
.orWhere('playerTwo.id = :playerTwoId', { playerTwoId: user.id })
|
||||
.getMany();
|
||||
.where('history.playerOne.id = :userOne', {userOne : user.id})
|
||||
.orWhere('history.playerTwo.id = :userTwo', {userTwo: user.id})
|
||||
.getMany()
|
||||
console.log("gZZZZZZZZZZZZamehistory")
|
||||
console.log(...gameHistory)
|
||||
let sendableHistory : SendableMatchHistory[] = []
|
||||
for (const history of gameHistory)
|
||||
{
|
||||
console.log(history.playerOne.username + 'ssssssssss')
|
||||
sendableHistory.push(new SendableMatchHistory(history))
|
||||
}
|
||||
return sendableHistory;
|
||||
console.log("sendable history")
|
||||
console.log(sendableHistory);
|
||||
return res.status(HttpStatus.OK).json(sendableHistory);
|
||||
}
|
||||
|
||||
async getRankingForAllUsers(currentUser : User) {
|
||||
@@ -323,6 +331,7 @@ export class GameService {
|
||||
matchHistory.playerOneResult = game.playerOneUsernameResult;
|
||||
matchHistory.playerTwoResult = game.playerTwoUsernameResult;
|
||||
const savedHistory = await this.matchHistory.save(matchHistory);
|
||||
console.log("MATCH HISTORYsssssssssss")
|
||||
console.log(savedHistory);
|
||||
return HttpStatus.OK
|
||||
}
|
||||
|
||||
@@ -16,6 +16,6 @@ export class SendableMatchHistory {
|
||||
this.playerOneUsername = matchHistory.playerOne.username;
|
||||
this.playerTwoUsername = matchHistory.playerTwo.username;
|
||||
this.playerOneResult = matchHistory.playerOneResult;
|
||||
this.playerTwoResult = matchHistory.playerTwoResult;
|
||||
this.playerTwoResult = matchHistory.playerTwoResult;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user