Vive le rouge !
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import { IsBoolean, IsNotEmpty, IsNumber, IsString } from "class-validator";
|
||||
|
||||
export class CreateGameDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
gameServerIdOfTheMatch : string
|
||||
@IsNumber()
|
||||
@IsNotEmpty()
|
||||
gameOptions: number
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
playerOneUsername : string
|
||||
@IsString()
|
||||
playerTwoUsername : string
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { IsBoolean, IsNotEmpty, IsNumber, IsString } from "class-validator";
|
||||
|
||||
export class UpdateGameDto {
|
||||
@IsNumber()
|
||||
@IsNotEmpty()
|
||||
playerOneUsernameResult : number
|
||||
@IsNumber()
|
||||
@IsNotEmpty()
|
||||
playerTwoUsernameResult : number
|
||||
@IsBoolean()
|
||||
isMatchIsFinished : boolean
|
||||
}
|
||||
@@ -11,15 +11,15 @@ export class Game {
|
||||
@Column()
|
||||
playerTwoUsername: string
|
||||
|
||||
@Column()
|
||||
@Column({default : 0, nullable : true})
|
||||
playerOneUsernameResult : number
|
||||
|
||||
@Column()
|
||||
@Column({default : 0, nullable : true})
|
||||
playerTwoUsernameResult : number
|
||||
|
||||
@Column()
|
||||
gameServerIdOfTheMatch: string
|
||||
|
||||
@Column({default: false}) //éric pourra trouver un meilleur mot : ongoing ?
|
||||
@Column({default: false, nullable : true}) //éric pourra trouver un meilleur mot : ongoing ?
|
||||
isMatchIsFinished: boolean
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { Body, Controller, Get, HttpException, HttpStatus, Post, Req, UseGuards } from '@nestjs/common';
|
||||
import { Console } from 'console';
|
||||
import { request } from 'http';
|
||||
import { use } from 'passport';
|
||||
import { AuthenticateGuard, TwoFactorGuard } from 'src/auth/42/guards/42guards';
|
||||
import { User } from 'src/users/entities/user.entity';
|
||||
import { UsersService } from 'src/users/users.service';
|
||||
import { CreateGameDto } from './dto/createGame.dto';
|
||||
import { GrantTicketDto } from './dto/grantTicket.dto';
|
||||
import { ValidateTicketDto } from './dto/validateTicket.dto';
|
||||
import { TokenGame } from './entity/tokenGame.entity';
|
||||
@@ -21,8 +23,8 @@ export class GameController {
|
||||
const user : User = req.user
|
||||
if (grantTicketDto.playerOneUsername != user.username)
|
||||
return new HttpException('You can\'t request a game for another person.', 403 )
|
||||
else if (user.status !== "connected")
|
||||
return new HttpException('You must not be in game...', HttpStatus.FORBIDDEN )
|
||||
// else if (user.status !== "connected")
|
||||
// return new HttpException('You must not be in game...', HttpStatus.FORBIDDEN )
|
||||
return this.gameService.generateToken(user, grantTicketDto);
|
||||
}
|
||||
|
||||
@@ -37,11 +39,12 @@ export class GameController {
|
||||
|
||||
|
||||
//N'est valable que pour le game-serveur.
|
||||
@Post('gameServer/validate')
|
||||
@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;
|
||||
}
|
||||
|
||||
@@ -72,4 +75,12 @@ export class GameController {
|
||||
return this.gameService.findInvitations(user);
|
||||
}
|
||||
|
||||
@Post('gameserver/creategame')
|
||||
async createGame(@Body() creategameDto : CreateGameDto)
|
||||
{
|
||||
return this.gameService.createGame(creategameDto);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import { Game } from './entity/game.entity';
|
||||
import { ValidateTicketDto } from './dto/validateTicket.dto';
|
||||
import { TokenGame } from './entity/tokenGame.entity';
|
||||
import { UsersService } from 'src/users/users.service';
|
||||
import { CreateGameDto } from './dto/createGame.dto';
|
||||
|
||||
@Injectable()
|
||||
export class GameService {
|
||||
@@ -37,9 +38,10 @@ export class GameService {
|
||||
|
||||
async generateToken(user : User, grantTicketDto : GrantTicketDto)
|
||||
{
|
||||
if (user.status === "In Game")
|
||||
return new HttpException("You can't play two games", HttpStatus.FORBIDDEN);
|
||||
else if (grantTicketDto.isGameIsWithInvitation === true)
|
||||
// if (user.status === "In Game")
|
||||
// return new HttpException("You can't play two games", HttpStatus.FORBIDDEN);
|
||||
// else
|
||||
if (grantTicketDto.isGameIsWithInvitation === true)
|
||||
{
|
||||
const secondUser : Partial<User> = await this.userService.findOneByUsername(user.id.toString(), grantTicketDto.playerTwoUsername)
|
||||
if (!secondUser)
|
||||
@@ -141,8 +143,8 @@ export class GameService {
|
||||
|
||||
async declineInvitation(user : User, token : string)
|
||||
{
|
||||
if (user.status === "In Game")
|
||||
return new HttpException("You must finish your game before decline.", HttpStatus.FORBIDDEN)
|
||||
// if (user.status === "In Game")
|
||||
// return new HttpException("You must finish your game before decline.", HttpStatus.FORBIDDEN)
|
||||
const tokenGame = await this.tokenGameRepository.createQueryBuilder('tokengame')
|
||||
.andWhere('tokengame.playerTwoUsername = :playerTwoUsername', {playerTwoUsername : user.username})
|
||||
.andWhere('tokengame.token = :token', {token : token})
|
||||
@@ -154,8 +156,8 @@ export class GameService {
|
||||
|
||||
async acceptInvitation(user : User, token : string)
|
||||
{
|
||||
if (user.status === "In Game")
|
||||
return new HttpException("You must finish your game before accept.", HttpStatus.FORBIDDEN)
|
||||
// if (user.status === "In Game")
|
||||
// return new HttpException("You must finish your game before accept.", HttpStatus.FORBIDDEN)
|
||||
const tokenGame = await this.tokenGameRepository.createQueryBuilder('tokenGame')
|
||||
.andWhere('tokenGame.playerTwoUsername = :playerTwoUsername', {playerTwoUsername : user.username})
|
||||
.andWhere('tokenGame.token = :token', {token : token})
|
||||
@@ -170,8 +172,8 @@ export class GameService {
|
||||
}
|
||||
|
||||
async requestIfAnotherUserHasRespondToquestForGame(user : User, token : string) {
|
||||
if (user.status === "In Game")
|
||||
return new HttpException("You can't do that.", HttpStatus.BAD_REQUEST)
|
||||
// if (user.status === "In Game")
|
||||
// return new HttpException("You can't do that.", HttpStatus.BAD_REQUEST)
|
||||
const tokenGame = await this.tokenGameRepository.createQueryBuilder('tokenGame')
|
||||
.where('tokenGame.token = :token', {token : token})
|
||||
.andWhere('tokenGame.isSecondUserAcceptedRequest = :isSecondUserAcceptedRequest', {isSecondUserAcceptedRequest : true})
|
||||
@@ -183,5 +185,16 @@ export class GameService {
|
||||
else if (!tokenGame)
|
||||
return new HttpException("Not Found", HttpStatus.NOT_FOUND)
|
||||
}
|
||||
|
||||
|
||||
async createGame(creategameDto : CreateGameDto)
|
||||
{
|
||||
const game = this.gameRepository.create(creategameDto)
|
||||
this.gameRepository.save(game);
|
||||
if (!game)
|
||||
return HttpStatus.INTERNAL_SERVER_ERROR
|
||||
console.log("200 retourné pour la création de partie")
|
||||
return HttpStatus.OK
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user