From a5125361d443434c8bfe4ffc76e5eff5e0dfd1ce Mon Sep 17 00:00:00 2001 From: Samuli Virtapohja <l4721@student.jamk.fi> Date: Mon, 24 Jun 2019 13:38:57 +0300 Subject: [PATCH] db setit mergetty --- package-lock.json | 41 ++++++++++--------------------------- src/game/game.controller.ts | 8 ++++++-- src/game/game.entity.ts | 11 ++++++---- src/game/game.service.ts | 16 +++++++++------ 4 files changed, 34 insertions(+), 42 deletions(-) diff --git a/package-lock.json b/package-lock.json index d6db2b3..05c4c11 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3125,8 +3125,7 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "aproba": { "version": "1.2.0", @@ -3147,14 +3146,12 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -3169,20 +3166,17 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -3299,8 +3293,7 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -3312,7 +3305,6 @@ "version": "1.0.0", "bundled": true, "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -3327,7 +3319,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -3335,14 +3326,12 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -3361,7 +3350,6 @@ "version": "0.5.1", "bundled": true, "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -3442,8 +3430,7 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -3455,7 +3442,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -3541,8 +3527,7 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "safer-buffer": { "version": "2.1.2", @@ -3578,7 +3563,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -3598,7 +3582,6 @@ "version": "3.0.1", "bundled": true, "dev": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -3642,14 +3625,12 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true } } }, diff --git a/src/game/game.controller.ts b/src/game/game.controller.ts index 9eb94eb..fdcc79e 100644 --- a/src/game/game.controller.ts +++ b/src/game/game.controller.ts @@ -37,7 +37,11 @@ export class GameController { @Post(':id') @UseGuards(new AuthGuard()) @UsePipes(new ValidationPipe()) - async createGroup(@User('id') person, @Param('id') id: string, @Body() data: GameGroupDTO) { + async createGroup( + @User('id') person, + @Param('id') id: string, + @Body() data: GameGroupDTO, + ) { try { return this.gameservice.createGroup(person, id, data); } catch (error) {} @@ -51,7 +55,7 @@ export class GameController { @Put('groups/:id') @UseGuards(new AuthGuard()) async joinGroup(@User('id') person, @Param('id') id) { - return this.gameservice.joinGroup(person, id) + return this.gameservice.joinGroup(person, id); } @Put('joinfaction') diff --git a/src/game/game.entity.ts b/src/game/game.entity.ts index 739e02a..1eefcd3 100644 --- a/src/game/game.entity.ts +++ b/src/game/game.entity.ts @@ -12,7 +12,10 @@ import { import { PersonEntity } from '../user/user.entity'; import { GameGroupEntity } from './group.entity'; import { FactionEntity, TaskEntity } from './faction.entity'; -import { MapDrawingEntity, Game_Person_MapDrawingEntity } from './coordinate.entity'; +import { + MapDrawingEntity, + Game_Person_MapDrawingEntity, +} from './coordinate.entity'; // table that stores all created games @Entity('Game') @@ -24,9 +27,9 @@ export class GameEntity { @Column({ type: 'json', nullable: true }) map: JSON; @Column('timestamp') startdate: Timestamp; @Column('timestamp') enddate: Timestamp; - + @OneToMany(type => FactionEntity, factions => factions.factionId) - factionsId: FactionEntity[]; + factions: FactionEntity[]; @OneToMany(type => Game_PersonEntity, game_persons => game_persons.game) game_persons: Game_PersonEntity[]; @OneToMany(type => GameGroupEntity, group => group.game) @@ -48,7 +51,7 @@ export class GameEntity { export class Game_PersonEntity { @PrimaryGeneratedColumn('uuid') gamepersonId: string; @Column({ type: 'text', nullable: true }) role: string; - @ManyToOne(type => FactionEntity, faction => faction.factionId) + @ManyToOne(type => FactionEntity, faction => faction) faction: FactionEntity; @ManyToOne(type => GameEntity, game => game.id) game: GameEntity; diff --git a/src/game/game.service.ts b/src/game/game.service.ts index 44b38fc..e4dd8c7 100644 --- a/src/game/game.service.ts +++ b/src/game/game.service.ts @@ -34,7 +34,7 @@ export class GameService { // else add the game to the database const game = await this.gameRepository.create({ ...gameData, - factionsId: gameData.factions, + factions: gameData.factions, }); await this.gameRepository.insert(game); const gamePerson = await this.game_PersonRepository.create({ @@ -63,7 +63,7 @@ export class GameService { // update game entry in db const updatedGame = await this.gameRepository.create({ ...gameData, - factionsId: null, + factions: null, }); updatedGame['id'] = id; const gameId = await this.gameRepository.save(updatedGame); @@ -176,10 +176,14 @@ export class GameService { // returns name and id of each game async listGames() { - const games = await this.gameRepository.find({ relations: ['factions'] }); - return games.map(game => { - return game.gameObject(); - }); + try { + const games = await this.gameRepository.find(); + return games.map(game => { + return game.gameObject(); + }); + } catch (error) { + return error; + } } // returns information about a game identified by id -- GitLab