diff --git a/src/game/faction.entity.ts b/src/game/faction.entity.ts index 214f487c0bada41f5416fc19982cff50f9b80943..135d73a4108b3191e29c9e8921f1fbf5dffc9a37 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 66ec21fb62efb28a7f47dc5bbd9949cbaa0b03f5..739e02a0a7bbd77b0267ba723e7a6b622af5ee83 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 ec89d51b81276bc07ef1a282b2f4329428013049..44b38fca6b800a960312599362ef1c6874b405b8 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 8af761ceaa198b9ced94e97101c07614c946a836..76f56300b3abd944e86a9c5bdbfb651e322e8ab6 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) {