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 { AuthenticateGuard, TwoFactorGuard } from 'src/auth/42/guards/42guards';
|
||||||
import { User } from 'src/users/entities/user.entity';
|
import { User } from 'src/users/entities/user.entity';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
@@ -21,11 +21,13 @@ export class GameController {
|
|||||||
return this.gameService.getMatchesForSpectator();
|
return this.gameService.getMatchesForSpectator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('match/history/:username')
|
@Get('match/history')
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@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);
|
return this.gameService.getMatchHistory(username, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,22 +49,30 @@ export class GameService {
|
|||||||
|
|
||||||
async getMatchHistory(username : string, @Res() res : Response)
|
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)
|
if (!user)
|
||||||
return res.status(HttpStatus.NOT_FOUND).json({message : "History for " + username + " not found"});
|
return res.status(HttpStatus.NOT_FOUND).json({message : "History for " + username + " not found"});
|
||||||
const gameHistory = await this.matchHistory
|
console.log(user.username + 'OK USERNAME')
|
||||||
.createQueryBuilder('history')
|
const gameHistory = await this.matchHistory.
|
||||||
|
createQueryBuilder('history')
|
||||||
.leftJoinAndSelect('history.playerOne', 'playerOne')
|
.leftJoinAndSelect('history.playerOne', 'playerOne')
|
||||||
.leftJoinAndSelect('history.playerTwo', 'playerTwo')
|
.leftJoinAndSelect('history.playerTwo', 'playerTwo')
|
||||||
.where('playerOne.id = :playerOneId', { playerOneId: user.id })
|
.where('history.playerOne.id = :userOne', {userOne : user.id})
|
||||||
.orWhere('playerTwo.id = :playerTwoId', { playerTwoId: user.id })
|
.orWhere('history.playerTwo.id = :userTwo', {userTwo: user.id})
|
||||||
.getMany();
|
.getMany()
|
||||||
|
console.log("gZZZZZZZZZZZZamehistory")
|
||||||
|
console.log(...gameHistory)
|
||||||
let sendableHistory : SendableMatchHistory[] = []
|
let sendableHistory : SendableMatchHistory[] = []
|
||||||
for (const history of gameHistory)
|
for (const history of gameHistory)
|
||||||
{
|
{
|
||||||
|
console.log(history.playerOne.username + 'ssssssssss')
|
||||||
sendableHistory.push(new SendableMatchHistory(history))
|
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) {
|
async getRankingForAllUsers(currentUser : User) {
|
||||||
@@ -323,6 +331,7 @@ export class GameService {
|
|||||||
matchHistory.playerOneResult = game.playerOneUsernameResult;
|
matchHistory.playerOneResult = game.playerOneUsernameResult;
|
||||||
matchHistory.playerTwoResult = game.playerTwoUsernameResult;
|
matchHistory.playerTwoResult = game.playerTwoUsernameResult;
|
||||||
const savedHistory = await this.matchHistory.save(matchHistory);
|
const savedHistory = await this.matchHistory.save(matchHistory);
|
||||||
|
console.log("MATCH HISTORYsssssssssss")
|
||||||
console.log(savedHistory);
|
console.log(savedHistory);
|
||||||
return HttpStatus.OK
|
return HttpStatus.OK
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,6 @@ export class SendableMatchHistory {
|
|||||||
this.playerOneUsername = matchHistory.playerOne.username;
|
this.playerOneUsername = matchHistory.playerOne.username;
|
||||||
this.playerTwoUsername = matchHistory.playerTwo.username;
|
this.playerTwoUsername = matchHistory.playerTwo.username;
|
||||||
this.playerOneResult = matchHistory.playerOneResult;
|
this.playerOneResult = matchHistory.playerOneResult;
|
||||||
this.playerTwoResult = matchHistory.playerTwoResult;
|
this.playerTwoResult = matchHistory.playerTwoResult;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -5,9 +5,9 @@
|
|||||||
import type { MatchHistory } from "./Match";
|
import type { MatchHistory } from "./Match";
|
||||||
|
|
||||||
export let user;
|
export let user;
|
||||||
let matchList: MatchHistory[] = [];
|
let matchList = [];
|
||||||
|
|
||||||
onMount( async() => {
|
onMount( async() => {
|
||||||
|
console.log(user.username + 'jjjjjjjjjjjjj')
|
||||||
matchList = await fetchMatchList(user.username);
|
matchList = await fetchMatchList(user.username);
|
||||||
console.log(matchList);
|
console.log(matchList);
|
||||||
// matchList = await mockMatchList(user.username);
|
// matchList = await mockMatchList(user.username);
|
||||||
@@ -15,8 +15,8 @@
|
|||||||
|
|
||||||
async function fetchMatchList(username: string)
|
async function fetchMatchList(username: string)
|
||||||
{
|
{
|
||||||
let url = `http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/game/match/history/${username}`;
|
let url = `http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/game/match/history?username=${username}`;
|
||||||
|
console.log(url + 'ffffffff')
|
||||||
return fetch(url)
|
return fetch(url)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|||||||
Reference in New Issue
Block a user