From 39308d365b8b2ed90fcbfe22bcf4c750c91ff6d2 Mon Sep 17 00:00:00 2001 From: L4168 <L4168@student.jamk.fi> Date: Fri, 14 Jun 2019 14:13:33 +0300 Subject: [PATCH] additional fixes for adding game to db --- src/game/game.controller.ts | 9 ++++++++- src/game/game.dto.ts | 7 ++++--- src/game/game.entity.ts | 1 + src/game/game.service.ts | 15 ++++++++++++--- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/game/game.controller.ts b/src/game/game.controller.ts index 99a7bfe..775d494 100644 --- a/src/game/game.controller.ts +++ b/src/game/game.controller.ts @@ -1,4 +1,4 @@ -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 { AuthGuard } from '../shared/auth.guard'; @@ -17,6 +17,13 @@ export class GameController { 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()) @UsePipes(new ValidationPipe()) @Post(':id') diff --git a/src/game/game.dto.ts b/src/game/game.dto.ts index b4607e3..7a8b493 100644 --- a/src/game/game.dto.ts +++ b/src/game/game.dto.ts @@ -20,9 +20,10 @@ export class GameDTO { @IsNotEmpty() @Length(1, 255) desc: string; + center: JSON; //@IsJSON() // doesn't accept with IsJSON, WIP to get validation for map - map: JSON; + map?: JSON; @IsDateString() @IsNotEmpty() startdate: string; @@ -35,9 +36,9 @@ export class GameDTO { each: true, }) // custom validation for array length (arr>min, arr<max) - @Validate(ArrayLength, [4, 8]) + //@Validate(ArrayLength, [4, 8]) passwords: string[]; - factions: FactionDTO[]; + factions?: FactionDTO[]; } export class FactionDTO { diff --git a/src/game/game.entity.ts b/src/game/game.entity.ts index af046da..d7c42c9 100644 --- a/src/game/game.entity.ts +++ b/src/game/game.entity.ts @@ -14,6 +14,7 @@ export class GameEntity { @PrimaryGeneratedColumn('uuid') id: string; @Column('text') name: string; @Column('text') desc: string; + @Column('json') center: JSON; @Column('json') map: JSON; @Column('timestamp') startdate: Timestamp; @Column('timestamp') enddate: Timestamp; diff --git a/src/game/game.service.ts b/src/game/game.service.ts index 87ec5c4..b909d10 100644 --- a/src/game/game.service.ts +++ b/src/game/game.service.ts @@ -32,7 +32,14 @@ export class GameService { factions: gameData.factions, }); 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({ where: { name: gameData.name }, }); @@ -43,8 +50,10 @@ export class GameService { game: gameid, }); await this.factionRepository.insert(name); - }); - return 'success'; + }); */ + return { + "message": "Game updated" + } } // checks the password, creates an entry in GamePerson table with associated role&faction -- GitLab