Skip to content
Snippets Groups Projects
Commit df9625ce authored by L4168's avatar L4168
Browse files

merge fixes

parent 1217a1d7
No related branches found
No related tags found
2 merge requests!59Development to master,!20Lippuboksi
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from 'typeorm'; import {
import { GameEntity } from './game.entity'; Entity,
Column,
PrimaryGeneratedColumn,
ManyToOne,
Timestamp,
} from 'typeorm';
import { GameEntity, Game_PersonEntity } from './game.entity';
import { FactionEntity } from './faction.entity'; import { FactionEntity } from './faction.entity';
@Entity('MapDrawing') @Entity('MapDrawing')
...@@ -10,8 +16,19 @@ export class MapDrawingEntity { ...@@ -10,8 +16,19 @@ export class MapDrawingEntity {
@Column({ type: 'json', nullable: true }) data: JSON; @Column({ type: 'json', nullable: true }) data: JSON;
@ManyToOne(type => FactionEntity, faction => faction.mapDrawings) @ManyToOne(type => FactionEntity, faction => faction.factionId)
faction: FactionEntity; faction: FactionEntity;
@ManyToOne(type => GameEntity, gameEntity => gameEntity.id) @ManyToOne(type => GameEntity, gameEntity => gameEntity.id)
gameId: GameEntity; gameId: GameEntity;
} }
@Entity('Game_Person_MapDrawing')
export class Game_Person_MapDrawingEntity {
@PrimaryGeneratedColumn('uuid') GPmapDrawingId: string;
@Column({ type: 'timestamp' }) GPCTimeStamp: Timestamp;
@ManyToOne(type => Game_PersonEntity, game_person => game_person.gamepersonId)
game_person: Game_PersonEntity;
@ManyToOne(type => MapDrawingEntity, map_drawing => map_drawing.mapDrawingId)
map_drawing: MapDrawingEntity;
}
...@@ -19,17 +19,9 @@ export class FactionEntity { ...@@ -19,17 +19,9 @@ export class FactionEntity {
@Column({ type: 'text' }) factionPassword: string; @Column({ type: 'text' }) factionPassword: string;
@Column({ type: 'float' }) multiplier: number; @Column({ type: 'float' }) multiplier: number;
@OneToMany(type => MapDrawingEntity, mapDrawings => mapDrawings.faction)
mapDrawings: MapDrawingEntity[];
@OneToMany(type => ScoreEntity, scores => scores.faction)
scores: ScoreEntity[];
@OneToMany(type => PowerUpEntity, powerUps => powerUps.factions)
powerUps: Faction_PowerUpEntity[];
@OneToMany(type => TaskEntity, tasks => tasks.faction)
tasks: TaskEntity[];
@OneToMany(type => Game_PersonEntity, game_persons => game_persons.faction) @OneToMany(type => Game_PersonEntity, game_persons => game_persons.faction)
game_persons: Game_PersonEntity[]; game_persons: Game_PersonEntity[];
@ManyToOne(type => GameEntity, game => game.factions) @ManyToOne(type => GameEntity, game => game.id)
game: GameEntity; game: GameEntity;
} }
...@@ -41,7 +33,7 @@ export class PowerUpEntity { ...@@ -41,7 +33,7 @@ export class PowerUpEntity {
@Column({ type: 'int' }) amount: number; @Column({ type: 'int' }) amount: number;
@Column({ type: 'time' }) cooldown: string; @Column({ type: 'time' }) cooldown: string;
@OneToMany(type => FactionEntity, factions => factions.powerUps) @OneToMany(type => FactionEntity, factions => factions.factionId)
factions: Faction_PowerUpEntity[]; factions: Faction_PowerUpEntity[];
} }
...@@ -49,7 +41,7 @@ export class PowerUpEntity { ...@@ -49,7 +41,7 @@ export class PowerUpEntity {
export class Faction_PowerUpEntity { export class Faction_PowerUpEntity {
@PrimaryGeneratedColumn('uuid') faction_powerUpId: string; @PrimaryGeneratedColumn('uuid') faction_powerUpId: string;
@ManyToOne(type => FactionEntity, faction => faction.powerUps) @ManyToOne(type => FactionEntity, faction => faction.factionId)
faction: FactionEntity; faction: FactionEntity;
@ManyToOne(type => PowerUpEntity, powerUp => powerUp.factions) @ManyToOne(type => PowerUpEntity, powerUp => powerUp.factions)
powerUp: PowerUpEntity; powerUp: PowerUpEntity;
...@@ -75,7 +67,7 @@ export class ScoreEntity { ...@@ -75,7 +67,7 @@ export class ScoreEntity {
@Column({ type: 'float' }) score: number; @Column({ type: 'float' }) score: number;
@Column({ type: 'timestamp' }) scoreTimeStamp: Timestamp; @Column({ type: 'timestamp' }) scoreTimeStamp: Timestamp;
@ManyToOne(type => FactionEntity, factionName => factionName.scores) @ManyToOne(type => FactionEntity, factionName => factionName.factionId)
faction: FactionEntity; faction: FactionEntity;
} }
...@@ -87,7 +79,7 @@ export class TaskEntity { ...@@ -87,7 +79,7 @@ export class TaskEntity {
@Column({ type: 'text' }) taskWinner: string; @Column({ type: 'text' }) taskWinner: string;
@Column({ type: 'bool' }) taskIsActive: boolean; @Column({ type: 'bool' }) taskIsActive: boolean;
@ManyToOne(type => FactionEntity, faction => faction.tasks) @ManyToOne(type => FactionEntity, faction => faction.factionId)
faction: FactionEntity; faction: FactionEntity;
/* @ManyToOne(type => PersonEntity, person => person.tasks) /* @ManyToOne(type => PersonEntity, person => person.tasks)
person: PersonEntity; */ person: PersonEntity; */
......
...@@ -25,8 +25,8 @@ export class GameEntity { ...@@ -25,8 +25,8 @@ export class GameEntity {
@Column({ type: 'json', nullable: true }) nodesettings?: JSON; @Column({ type: 'json', nullable: true }) nodesettings?: JSON;
@Column('timestamp') startdate: Timestamp; @Column('timestamp') startdate: Timestamp;
@Column('timestamp') enddate: Timestamp; @Column('timestamp') enddate: Timestamp;
@OneToMany(type => FactionEntity, faction => faction.game) @OneToMany(type => FactionEntity, factions => factions.factionId)
factions: FactionEntity[]; factionsId: FactionEntity[];
@OneToMany(type => Game_PersonEntity, game_persons => game_persons.game) @OneToMany(type => Game_PersonEntity, game_persons => game_persons.game)
game_persons: Game_PersonEntity[]; game_persons: Game_PersonEntity[];
@OneToMany(type => GameGroupEntity, group => group.game) @OneToMany(type => GameGroupEntity, group => group.game)
...@@ -48,11 +48,11 @@ export class GameEntity { ...@@ -48,11 +48,11 @@ export class GameEntity {
export class Game_PersonEntity { export class Game_PersonEntity {
@PrimaryGeneratedColumn('uuid') gamepersonId: string; @PrimaryGeneratedColumn('uuid') gamepersonId: string;
@Column({ type: 'text', nullable: true }) role: string; @Column({ type: 'text', nullable: true }) role: string;
@ManyToOne(type => FactionEntity, faction => faction.game_persons) @ManyToOne(type => FactionEntity, faction => faction.factionId)
faction: FactionEntity; faction: FactionEntity;
@ManyToOne(type => GameEntity, game => game.game_persons) @ManyToOne(type => GameEntity, game => game.id)
game: GameEntity; game: GameEntity;
@ManyToOne(type => PersonEntity, person => person.game_persons) @ManyToOne(type => PersonEntity, person => person.id)
person: PersonEntity; person: PersonEntity;
@OneToOne(type => GameGroupEntity, group => group.leader, { @OneToOne(type => GameGroupEntity, group => group.leader, {
onDelete: 'CASCADE', onDelete: 'CASCADE',
...@@ -71,17 +71,11 @@ export class ObjectivePointEntity { ...@@ -71,17 +71,11 @@ export class ObjectivePointEntity {
@PrimaryGeneratedColumn('uuid') objectivePointId: string; @PrimaryGeneratedColumn('uuid') objectivePointId: string;
@Column({ type: 'text' }) objectivePointDescription: string; @Column({ type: 'text' }) objectivePointDescription: string;
@Column({ type: 'float' }) objectivePointMultiplier: number; @Column({ type: 'float' }) objectivePointMultiplier: number;
//@Column('boolean') captureStatus: boolean;
@ManyToOne(type => MapDrawingEntity, coordinate => coordinate.data) @ManyToOne(type => MapDrawingEntity, coordinate => coordinate.data)
coordinate: MapDrawingEntity; coordinate: MapDrawingEntity;
@ManyToOne(type => GameEntity, game => game.objective_points) @ManyToOne(type => GameEntity, game => game.objective_points)
game: GameEntity; game: GameEntity;
@OneToMany(
type => ObjectivePoint_HistoryEntity,
op_history => op_history.objective_point,
)
op_history: ObjectivePoint_HistoryEntity[];
} }
@Entity('ObjectivePoint_History') @Entity('ObjectivePoint_History')
...@@ -95,7 +89,7 @@ export class ObjectivePoint_HistoryEntity { ...@@ -95,7 +89,7 @@ export class ObjectivePoint_HistoryEntity {
owner: FactionEntity; owner: FactionEntity;
@ManyToOne( @ManyToOne(
type => ObjectivePointEntity, type => ObjectivePointEntity,
objective_point => objective_point.op_history, objective_point => objective_point.objectivePointId,
) )
objective_point: ObjectivePointEntity; objective_point: ObjectivePointEntity;
} }
...@@ -12,6 +12,7 @@ import { ...@@ -12,6 +12,7 @@ import {
import { PersonEntity } from '../user/user.entity'; import { PersonEntity } from '../user/user.entity';
import { GameGroupEntity } from './group.entity'; import { GameGroupEntity } from './group.entity';
import { FactionEntity } from './faction.entity'; import { FactionEntity } from './faction.entity';
import { NotificationModule } from '../notifications/notifications.module';
@Module({ @Module({
imports: [ imports: [
...@@ -24,6 +25,7 @@ import { FactionEntity } from './faction.entity'; ...@@ -24,6 +25,7 @@ import { FactionEntity } from './faction.entity';
ObjectivePointEntity, ObjectivePointEntity,
ObjectivePoint_HistoryEntity, ObjectivePoint_HistoryEntity,
]), ]),
NotificationModule,
], ],
controllers: [GameController], controllers: [GameController],
providers: [GameService], providers: [GameService],
......
...@@ -47,7 +47,7 @@ export class GameService { ...@@ -47,7 +47,7 @@ export class GameService {
// else add the game to the database // else add the game to the database
const game = await this.gameRepository.create({ const game = await this.gameRepository.create({
...gameData, ...gameData,
factions: gameData.factions, factionsId: gameData.factions,
}); });
await this.gameRepository.insert(game); await this.gameRepository.insert(game);
const gamePerson = await this.game_PersonRepository.create({ const gamePerson = await this.game_PersonRepository.create({
...@@ -76,7 +76,7 @@ export class GameService { ...@@ -76,7 +76,7 @@ export class GameService {
// update game entry in db // update game entry in db
const updatedGame = await this.gameRepository.create({ const updatedGame = await this.gameRepository.create({
...gameData, ...gameData,
factions: null, factionsId: null,
objective_points: null, objective_points: null,
}); });
updatedGame['id'] = id; updatedGame['id'] = id;
......
import { import {
Entity, Entity,
Column, Column,
PrimaryGeneratedColumn, PrimaryGeneratedColumn,
Timestamp, Timestamp,
ManyToOne, ManyToOne,
} from 'typeorm'; } from 'typeorm';
import { PersonEntity } from '../user/user.entity'; import { PersonEntity } from '../user/user.entity';
/* /*
Entity: MapMarker Entity: MapMarker
- represents data that database contains on mapmarker - represents data that database contains on mapmarker
*/ */
@Entity('MapMarker') @Entity('MapMarker')
export class MapMarkerEntity { export class MapMarkerEntity {
@PrimaryGeneratedColumn('uuid') id: string; @PrimaryGeneratedColumn('uuid') id: string;
@Column({ type: 'text', nullable: true }) latitude: string; @Column({ type: 'text', nullable: true }) latitude: string;
@Column({ type: 'text', nullable: true }) longitude: string; @Column({ type: 'text', nullable: true }) longitude: string;
@Column({ type: 'timestamp' }) timestamp: Timestamp; @Column({ type: 'timestamp' }) timestamp: Timestamp;
@Column({ type: 'json', nullable: true }) features: JSON; @Column({ type: 'json', nullable: true }) features: JSON;
@ManyToOne(type => PersonEntity, player => player.markers) }
player: PersonEntity;
}
\ No newline at end of file
import { Injectable, HttpException, HttpStatus } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { Repository, In } from 'typeorm'; import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm'; import { InjectRepository } from '@nestjs/typeorm';
import { MapMarkerEntity } from './mapmarker.entity'; import { MapMarkerEntity } from './mapmarker.entity';
import { MapMarkerDTO } from './mapmarker.dto'; import { MapMarkerDTO } from './mapmarker.dto';
import { PersonEntity } from '../user/user.entity'; import { PersonEntity } from '../user/user.entity';
import { userInfo } from 'os';
@Injectable() @Injectable()
export class MapMarkerService { export class MapMarkerService {
...@@ -29,12 +28,11 @@ export class MapMarkerService { ...@@ -29,12 +28,11 @@ export class MapMarkerService {
//create&copy entity properties //create&copy entity properties
const location = await this.mapmarkerRepository.create({ const location = await this.mapmarkerRepository.create({
...data, ...data,
player: user,
}); });
// insert created entity NOTE: insert method doesn't check for duplicates. // insert created entity NOTE: insert method doesn't check for duplicates.
await this.mapmarkerRepository.insert(location); await this.mapmarkerRepository.insert(location);
// return data and player id&name // return data and player id&name
return { ...data, player: location.player.nameObject() }; return { ...data };
} catch (error) { } catch (error) {
return error; return error;
} }
...@@ -49,7 +47,7 @@ export class MapMarkerService { ...@@ -49,7 +47,7 @@ export class MapMarkerService {
}); });
// return markers from database with said playerdata // return markers from database with said playerdata
return markers.map(marker => { return markers.map(marker => {
return { ...marker, player: marker.player.nameObject() }; return { ...marker };
}); });
} catch (error) { } catch (error) {
return error.message; return error.message;
......
...@@ -6,5 +6,6 @@ import { TypeOrmModule } from '@nestjs/typeorm'; ...@@ -6,5 +6,6 @@ import { TypeOrmModule } from '@nestjs/typeorm';
@Module({ @Module({
imports: [TypeOrmModule.forFeature([NotificationEntity])], imports: [TypeOrmModule.forFeature([NotificationEntity])],
providers: [NotificationGateway], providers: [NotificationGateway],
exports: [NotificationGateway],
}) })
export class NotificationModule {} export class NotificationModule {}
const AccessControl = require('accesscontrol');
const grants = {
admin: {
mapmarker: {
'create:any': [],
'delete:any': [],
'read:any': [],
'update:any': [],
},
powerup: {
'create:any': [],
'delete:any': [],
'read:any': [],
'update:any': [],
},
faction: {
'create:any': [],
'delete:any': [],
'read:any': [],
'update:any': [],
},
players: {
'create:any': [],
'delete:any': [],
'read:any': [],
'update:any': [],
},
},
faction_leader: {
mapmarker: {
'create:own': [],
'delete:own': [],
'read:own': [],
},
powerup: {
'read:own': [],
},
faction: {
'read:own': [],
'update:own': [],
},
players: {
'read:own': [],
'update:own': [],
},
},
//player & spectator
};
const ac = new AccessControl(grants);
/*const express = require ('express');
const router express.Router;
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')
.readOwn('mapmarker')
.grant('admin') // switch to another role without breaking the chain
.extend('user') // inherit role capabilities. also takes an array
.updateAny('mapmarker', ['title']) // explicitly defined attributes
.deleteAny('mapmarker')
.readAny('mapmarker');
//const
let permission = ac.can('user').createOwn('mapmarker');
console.log(permission.granted); // —> true
console.log(permission.attributes); // —> ['*'] (all attributes)
permission = ac.can('admin').updateAny('mapmarker');
console.log(permission.granted); // —> true
console.log(permission.attributes); // —> ['title']
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) {
if (err || !data) return res.status(404).end();
// filter data by permission attributes and send.
res.json(permission.filter(data));
});
} else {
// resource is forbidden for this user/role
res.status(403).end();
}
});*/
...@@ -7,17 +7,13 @@ import { ...@@ -7,17 +7,13 @@ import {
} from 'typeorm'; } from 'typeorm';
import * as bcrypt from 'bcryptjs'; import * as bcrypt from 'bcryptjs';
import * as jwt from 'jsonwebtoken'; import * as jwt from 'jsonwebtoken';
import { MapMarkerEntity } from 'src/mapmarkers/mapmarker.entity'; import { Game_PersonEntity } from '../game/game.entity';
import {TaskEntity} from '../game/faction.entity'
import {Game_PersonEntity} from '../game/game.entity'
@Entity('Person') @Entity('Person')
export class PersonEntity { export class PersonEntity {
@PrimaryGeneratedColumn('uuid') id: string; @PrimaryGeneratedColumn('uuid') id: string;
@Column({ type: 'text', unique: true }) name: string; @Column({ type: 'text', unique: true }) name: string;
@Column('text') password: string; @Column('text') password: string;
@OneToMany(type => MapMarkerEntity, marker => marker.player)
markers: MapMarkerEntity[];
@OneToMany(type => Game_PersonEntity, game_persons => game_persons.person) @OneToMany(type => Game_PersonEntity, game_persons => game_persons.person)
game_persons: Game_PersonEntity[]; game_persons: Game_PersonEntity[];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment