Skip to content
Snippets Groups Projects
Commit 39308d36 authored by L4168's avatar L4168
Browse files

additional fixes for adding game to db

parent aa922564
No related branches found
No related tags found
1 merge request!59Development to master
import { Controller, Post, UseGuards, Body, Get, Param, UsePipes } from '@nestjs/common'; import { Controller, Post, UseGuards, Body, Get, Param, UsePipes, Put } from '@nestjs/common';
import { GameService } from './game.service'; import { GameService } from './game.service';
import { AuthGuard } from '../shared/auth.guard'; import { AuthGuard } from '../shared/auth.guard';
...@@ -17,6 +17,13 @@ export class GameController { ...@@ -17,6 +17,13 @@ export class GameController {
return this.gameservice.createNewGame(person, body); return this.gameservice.createNewGame(person, body);
} }
@Put(':id')
@UseGuards(new AuthGuard())
@UsePipes(new ValidationPipe())
async editGame(@Param('id') id: string, @Body() body: GameDTO) {
return this.gameservice.editGame(body);
}
@UseGuards(new AuthGuard()) @UseGuards(new AuthGuard())
@UsePipes(new ValidationPipe()) @UsePipes(new ValidationPipe())
@Post(':id') @Post(':id')
......
...@@ -20,9 +20,10 @@ export class GameDTO { ...@@ -20,9 +20,10 @@ export class GameDTO {
@IsNotEmpty() @IsNotEmpty()
@Length(1, 255) @Length(1, 255)
desc: string; desc: string;
center: JSON;
//@IsJSON() //@IsJSON()
// doesn't accept with IsJSON, WIP to get validation for map // doesn't accept with IsJSON, WIP to get validation for map
map: JSON; map?: JSON;
@IsDateString() @IsDateString()
@IsNotEmpty() @IsNotEmpty()
startdate: string; startdate: string;
...@@ -35,9 +36,9 @@ export class GameDTO { ...@@ -35,9 +36,9 @@ export class GameDTO {
each: true, each: true,
}) })
// custom validation for array length (arr>min, arr<max) // custom validation for array length (arr>min, arr<max)
@Validate(ArrayLength, [4, 8]) //@Validate(ArrayLength, [4, 8])
passwords: string[]; passwords: string[];
factions: FactionDTO[]; factions?: FactionDTO[];
} }
export class FactionDTO { export class FactionDTO {
......
...@@ -14,6 +14,7 @@ export class GameEntity { ...@@ -14,6 +14,7 @@ export class GameEntity {
@PrimaryGeneratedColumn('uuid') id: string; @PrimaryGeneratedColumn('uuid') id: string;
@Column('text') name: string; @Column('text') name: string;
@Column('text') desc: string; @Column('text') desc: string;
@Column('json') center: JSON;
@Column('json') map: JSON; @Column('json') map: JSON;
@Column('timestamp') startdate: Timestamp; @Column('timestamp') startdate: Timestamp;
@Column('timestamp') enddate: Timestamp; @Column('timestamp') enddate: Timestamp;
......
...@@ -32,7 +32,14 @@ export class GameService { ...@@ -32,7 +32,14 @@ export class GameService {
factions: gameData.factions, factions: gameData.factions,
}); });
await this.gameRepository.insert(game); await this.gameRepository.insert(game);
// get the id of the game created to pass it to factions table return {
"message": "New game added"
};
}
// edit already created game
async editGame(gamedata) {
/* // get the id of the game created to pass it to factions table
const gameid = await this.gameRepository.findOne({ const gameid = await this.gameRepository.findOne({
where: { name: gameData.name }, where: { name: gameData.name },
}); });
...@@ -43,8 +50,10 @@ export class GameService { ...@@ -43,8 +50,10 @@ export class GameService {
game: gameid, game: gameid,
}); });
await this.factionRepository.insert(name); await this.factionRepository.insert(name);
}); }); */
return 'success'; return {
"message": "Game updated"
}
} }
// checks the password, creates an entry in GamePerson table with associated role&faction // checks the password, creates an entry in GamePerson table with associated role&faction
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment