From 7ddc2255d80d07da5d2ade22d070826e00a95dc8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marko=20Syd=C3=A4nmaa?= <L4072@student.jamk.fi>
Date: Mon, 24 Jun 2019 12:44:16 +0300
Subject: [PATCH] =?UTF-8?q?En=C3=A4=C3=A4n=20ei=20js=20valita?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/game/faction.entity.ts     | 17 ++++++++++++-----
 src/game/game.entity.ts        |  2 ++
 src/game/game.service.ts       |  6 +++---
 src/shared/roles.controller.ts | 10 ++++++----
 4 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/src/game/faction.entity.ts b/src/game/faction.entity.ts
index 214f487..135d73a 100644
--- a/src/game/faction.entity.ts
+++ b/src/game/faction.entity.ts
@@ -19,7 +19,9 @@ export class FactionEntity {
   @Column({ type: 'text' }) factionPassword: string;
   @Column({ type: 'float' }) multiplier: number;
 
-  @ManyToOne(type => GameEntity, gameEntity => gameEntity.id)
+  @OneToMany(type => Game_PersonEntity, game_persons => game_persons.faction)
+  game_persons: Game_PersonEntity[];
+  @ManyToOne(type => GameEntity, game => game.id)
   gameId: GameEntity;
 }
 
@@ -30,6 +32,9 @@ export class PowerUpEntity {
   @Column({ type: 'text' }) powerUpDescription: string;
   @Column({ type: 'int' }) amount: number;
   @Column({ type: 'time' }) cooldown: string;
+
+  @OneToMany(type => FactionEntity, factions => factions.factionId)
+  factions: Faction_PowerUpEntity[];
 }
 
 @Entity('Faction_PowerUp')
@@ -38,8 +43,10 @@ export class Faction_PowerUpEntity {
 
   @ManyToOne(type => FactionEntity, faction => faction.factionId)
   faction: FactionEntity;
-  @ManyToOne(type => PowerUpEntity, powerUp => powerUp.powerUpId)
+  @ManyToOne(type => PowerUpEntity, powerUp => powerUp.factions)
   powerUp: PowerUpEntity;
+  @OneToMany(type => FP_HistoryEntity, histories => histories.faction_PowerUp)
+  histories: FP_HistoryEntity[];
 }
 
 @Entity('FP_History')
@@ -49,7 +56,7 @@ export class FP_HistoryEntity {
 
   @ManyToOne(
     type => Faction_PowerUpEntity,
-    faction_PowerUp => faction_PowerUp.faction_powerUpId,
+    faction_PowerUp => faction_PowerUp.histories,
   )
   faction_PowerUp: Faction_PowerUpEntity;
 }
@@ -74,6 +81,6 @@ export class TaskEntity {
 
   @ManyToOne(type => FactionEntity, faction => faction.factionId)
   faction: FactionEntity;
-  @ManyToOne(type => Game_PersonEntity, person => person.gamepersonId)
-  personId: Game_PersonEntity;
+  /*     @ManyToOne(type => PersonEntity, person => person.tasks)
+    person: PersonEntity; */
 }
diff --git a/src/game/game.entity.ts b/src/game/game.entity.ts
index 66ec21f..739e02a 100644
--- a/src/game/game.entity.ts
+++ b/src/game/game.entity.ts
@@ -25,6 +25,8 @@ export class GameEntity {
   @Column('timestamp') startdate: Timestamp;
   @Column('timestamp') enddate: Timestamp;
   
+  @OneToMany(type => FactionEntity, factions => factions.factionId)
+  factionsId: FactionEntity[];
   @OneToMany(type => Game_PersonEntity, game_persons => game_persons.game)
   game_persons: Game_PersonEntity[];
   @OneToMany(type => GameGroupEntity, group => group.game)
diff --git a/src/game/game.service.ts b/src/game/game.service.ts
index ec89d51..44b38fc 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,
-        factions: gameData.factions,
+        factionsId: 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,
-        factions: null,
+        factionsId: null,
       });
       updatedGame['id'] = id;
       const gameId = await this.gameRepository.save(updatedGame);
@@ -78,7 +78,7 @@ export class GameService {
           if (!Object.values(factionNames).includes(faction.factionName)) {
             let name = await this.factionRepository.create({
               ...faction,
-              game: gameId,
+              gameId: gameId,
             });
             await this.factionRepository.insert(name);
           }
diff --git a/src/shared/roles.controller.ts b/src/shared/roles.controller.ts
index 8af761c..76f5630 100644
--- a/src/shared/roles.controller.ts
+++ b/src/shared/roles.controller.ts
@@ -45,14 +45,15 @@ const grants = {
             "update:own": []
         }
     }
+    //player & spectator
 };
 
 const ac = new AccessControl(grants);
 
 /*const express = require ('express');
 const router express.Router;
-*/
-/*const ac = new AccessControl();
+
+const ac = new AccessControl();
 ac.grant('faction_leader')                    // define new or modify existing role. also takes an array.
     .createOwn('mapmarker')             // equivalent to .createOwn('video', ['*'])
     .deleteOwn('mapmarker')
@@ -63,7 +64,8 @@ ac.grant('faction_leader')                    // define new or modify existing r
     .deleteAny('mapmarker')
     .readAny('mapmarker');
 
-/*const*//*let permission = ac.can('user').createOwn('mapmarker');
+//const
+let permission = ac.can('user').createOwn('mapmarker');
 console.log(permission.granted);    // —> true
 console.log(permission.attributes); // —> ['*'] (all attributes)
 
@@ -71,7 +73,7 @@ permission = ac.can('admin').updateAny('mapmarker');
 console.log(permission.granted);    // —> true
 console.log(permission.attributes); // —> ['title']
 
-/*router.get('/videos/:title', function (req, res, next) {
+router.get('/videos/:title', function (req, res, next) {
     const permission = ac.can(req.user.role).readAny('video');
     if (permission.granted) {
         Video.find(req.params.title, function (err, data) {
-- 
GitLab