From e92c2d8b9962475c303315d1123b6b54bbc91b11 Mon Sep 17 00:00:00 2001
From: L4168 <L4168@student.jamk.fi>
Date: Wed, 26 Jun 2019 14:29:06 +0300
Subject: [PATCH] fixing game list bug

---
 src/game/coordinate.entity.ts | 14 ++++++++++----
 src/game/faction.entity.ts    |  8 ++++++++
 src/game/game.entity.ts       |  2 +-
 3 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/src/game/coordinate.entity.ts b/src/game/coordinate.entity.ts
index 851bb65..f1a2eff 100644
--- a/src/game/coordinate.entity.ts
+++ b/src/game/coordinate.entity.ts
@@ -2,21 +2,27 @@ import {
   Entity,
   Column,
   PrimaryGeneratedColumn,
+  OneToMany,
   ManyToOne,
+  PrimaryColumn,
   Timestamp,
 } from 'typeorm';
-import { GameEntity, Game_PersonEntity } from './game.entity';
+import {
+  Game_PersonEntity,
+  ObjectivePointEntity,
+  GameEntity,
+} from './game.entity';
 import { FactionEntity } from './faction.entity';
 
 @Entity('MapDrawing')
 export class MapDrawingEntity {
   @PrimaryGeneratedColumn('uuid') mapDrawingId: string;
-  @Column({ type: 'bool' }) drawingIsActive: boolean;
-  @Column({ type: 'time' }) drawingValidTill: string;
+  @Column({ type: 'bool', nullable: true }) drawingIsActive: boolean;
+  @Column({ type: 'time', nullable: true }) drawingValidTill: string;
 
   @Column({ type: 'json', nullable: true }) data: JSON;
 
-  @ManyToOne(type => FactionEntity, faction => faction.factionId)
+  @ManyToOne(type => FactionEntity, faction => faction.mapDrawings)
   faction: FactionEntity;
   @ManyToOne(type => GameEntity, gameEntity => gameEntity.id)
   gameId: GameEntity;
diff --git a/src/game/faction.entity.ts b/src/game/faction.entity.ts
index 4c15c86..b8ce816 100644
--- a/src/game/faction.entity.ts
+++ b/src/game/faction.entity.ts
@@ -8,6 +8,7 @@ import {
 } from 'typeorm';
 import { GameEntity } from './game.entity';
 import { Game_PersonEntity } from './game.entity';
+import { MapDrawingEntity } from './coordinate.entity';
 
 //Faction, PowerUp, Faction_powerUp, FP_History, Score
 
@@ -22,6 +23,13 @@ export class FactionEntity {
   game_persons: Game_PersonEntity[];
   @ManyToOne(type => GameEntity, game => game.id)
   gameId: GameEntity;
+  @OneToMany(type => MapDrawingEntity, mapDrawings => mapDrawings.faction)
+  mapDrawings: MapDrawingEntity[];
+
+  factionObject() {
+    const { factionId, factionName, gameId } = this;
+    return { factionId, factionName, gameId };
+  }
 }
 
 @Entity('PowerUp')
diff --git a/src/game/game.entity.ts b/src/game/game.entity.ts
index b8bf9ae..c4e0424 100644
--- a/src/game/game.entity.ts
+++ b/src/game/game.entity.ts
@@ -29,7 +29,7 @@ export class GameEntity {
   @Column('timestamp') startdate: Timestamp;
   @Column('timestamp') enddate: Timestamp;
 
-  @OneToMany(type => FactionEntity, factions => factions.factionId)
+  @OneToMany(type => FactionEntity, factions => factions.gameId)
   factions: FactionEntity[];
   @OneToMany(type => Game_PersonEntity, game_persons => game_persons.game)
   game_persons: Game_PersonEntity[];
-- 
GitLab