Ajout du ranking côté back, reste à l'implémenter côté front
This commit is contained in:
@@ -16,6 +16,16 @@ import { GameService } from './game.service';
|
||||
export class GameController {
|
||||
constructor (private readonly gameService : GameService) { }
|
||||
|
||||
|
||||
@Get('ranking')
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
async getRankingForAllUsers(@Req() req)
|
||||
{
|
||||
const currentUser : User = req.user
|
||||
return this.gameService.getRankingForAllUsers(currentUser);
|
||||
}
|
||||
|
||||
@Post('ticket')
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@@ -38,17 +48,6 @@ export class GameController {
|
||||
return this.gameService.requestIfAnotherUserHasRespondToquestForGame(user, token);
|
||||
}
|
||||
|
||||
|
||||
//N'est valable que pour le game-serveur.
|
||||
@Post('gameserver/validate')
|
||||
async validateTicket(@Body() validateTicketDto : ValidateTicketDto, @Req() request)
|
||||
{
|
||||
if (await this.gameService.validateToken(validateTicketDto) === false)
|
||||
return new HttpException("The token is not valid", HttpStatus.NOT_FOUND);
|
||||
console.log("200 retourné côté nest")
|
||||
return HttpStatus.OK;
|
||||
}
|
||||
|
||||
@Post('decline')
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@@ -76,6 +75,17 @@ export class GameController {
|
||||
return this.gameService.findInvitations(user);
|
||||
}
|
||||
|
||||
//
|
||||
//N'est valable que pour le game-serveur.
|
||||
@Post('gameserver/validate')
|
||||
async validateTicket(@Body() validateTicketDto : ValidateTicketDto, @Req() request)
|
||||
{
|
||||
if (await this.gameService.validateToken(validateTicketDto) === false)
|
||||
return new HttpException("The token is not valid", HttpStatus.NOT_FOUND);
|
||||
console.log("200 retourné côté nest")
|
||||
return HttpStatus.OK;
|
||||
}
|
||||
|
||||
@Post('gameserver/creategame')
|
||||
async createGame(@Body() creategameDto : CreateGameDto)
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@ import { TokenGame } from './entity/tokenGame.entity';
|
||||
import { UsersService } from 'src/users/users.service';
|
||||
import { CreateGameDto } from './dto/createGame.dto';
|
||||
import { UpdateGameDto } from './dto/updateGame.dto';
|
||||
import { FriendshipService } from 'src/friendship/friendship.service';
|
||||
|
||||
@Injectable()
|
||||
export class GameService {
|
||||
@@ -21,9 +22,27 @@ export class GameService {
|
||||
private readonly userRepository : Repository<User>,
|
||||
@InjectRepository(TokenGame)
|
||||
private readonly tokenGameRepository : Repository<TokenGame>,
|
||||
private readonly userService : UsersService
|
||||
private readonly userService : UsersService,
|
||||
private readonly friendShipService : FriendshipService
|
||||
) { }
|
||||
|
||||
async getRankingForAllUsers(currentUser : User) {
|
||||
const users = await this.userRepository.createQueryBuilder("user")
|
||||
.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 })
|
||||
}
|
||||
return partialUser;
|
||||
}
|
||||
|
||||
|
||||
async encryptToken(toEncrypt : string) : Promise<string> {
|
||||
const iv = randomBytes(16);
|
||||
const password = process.env.TICKET_FOR_PLAYING_GAME_SECRET + new Date();
|
||||
|
||||
@@ -11,6 +11,10 @@ server {
|
||||
proxy_pass http://backend_dev:3000;
|
||||
}
|
||||
|
||||
location /api/v2/game/gameserver {
|
||||
deny all;
|
||||
}
|
||||
|
||||
location /pong {
|
||||
proxy_pass http://game_server:8042/pong;
|
||||
proxy_http_version 1.1;
|
||||
|
||||
Reference in New Issue
Block a user