Skip to content
Snippets Groups Projects
Commit e60ff46c authored by Samuli Virtapohja's avatar Samuli Virtapohja
Browse files

remove getplayers from replay.controller

parents 19b47e2c 05626522
No related branches found
No related tags found
3 merge requests!59Development to master,!54Development to testing,!52Commenting to Development
Showing
with 80 additions and 90 deletions
...@@ -9,12 +9,18 @@ import { ...@@ -9,12 +9,18 @@ import {
import { GameEntity } from '../game/game.entity'; import { GameEntity } from '../game/game.entity';
import { FactionEntity } from '../faction/faction.entity'; import { FactionEntity } from '../faction/faction.entity';
//////////////////////////////////////////////////////////////////////
/// Entities for different drawings in game and their histories ///
//////////////////////////////////////////////////////////////////////
@Entity('MapDrawing') @Entity('MapDrawing')
export class MapDrawingEntity { export class MapDrawingEntity {
@PrimaryGeneratedColumn('uuid') mapDrawingId: string; @PrimaryGeneratedColumn('uuid') mapDrawingId: string;
@Column({ type: 'bool', nullable: true }) drawingIsActive: boolean; @Column({ type: 'bool', nullable: true }) drawingIsActive: boolean;
@Column({ type: 'json', nullable: true }) data: JSON; @Column({ type: 'json', nullable: true }) data: JSON;
// When Faction or game that has the drawing in question is deleted from
// the database, the drawing is also deleted
@ManyToOne(type => FactionEntity, faction => faction.mapDrawings, { @ManyToOne(type => FactionEntity, faction => faction.mapDrawings, {
onDelete: 'CASCADE', onDelete: 'CASCADE',
}) })
...@@ -42,6 +48,7 @@ export class MapDrawingHistoryEntity { ...@@ -42,6 +48,7 @@ export class MapDrawingHistoryEntity {
@Column('bool') drawingIsActive: boolean; @Column('bool') drawingIsActive: boolean;
@Column('json') data: JSON; @Column('json') data: JSON;
// If drawing is deleted, it's histories are deleted also
@ManyToOne(() => MapDrawingEntity, mapDrawing => mapDrawing.mapDrawingId, { @ManyToOne(() => MapDrawingEntity, mapDrawing => mapDrawing.mapDrawingId, {
onDelete: 'CASCADE', onDelete: 'CASCADE',
}) })
......
import { import {
Controller, Controller,
Put, Put,
UseGuards,
Get, Get,
Param, Param,
UsePipes, UsePipes,
...@@ -16,13 +15,16 @@ import { Roles, GameStates } from '../shared/guard.decorator'; ...@@ -16,13 +15,16 @@ import { Roles, GameStates } from '../shared/guard.decorator';
import { MapDrawingDTO } from './mapdrawing.dto'; import { MapDrawingDTO } from './mapdrawing.dto';
import { GamePerson } from 'src/game/gameperson.decorator'; import { GamePerson } from 'src/game/gameperson.decorator';
/* //////////////////////////////////////////////////////////////////////////
DrawController /// DrawController ///
/// ///
/// Functions either insert or return MapDrawing data, ///
/// Insert functions require user to have proper role (either gm ///
/// or commander) in the game to be able store the data: ///
/// MapDrawingDTO data to database. ///
/// Data return functions require atleast spectator role. ///
//////////////////////////////////////////////////////////////////////////
Functions either insert or return MapDrawing data,
Insert functions require user to have proper role (either gm or commander) in the game to be able store the ddata: MapDrawingDTOata to database.
Data return functions require atleast spectator role.
*/
@Controller('draw') @Controller('draw')
export class DrawController { export class DrawController {
constructor(private drawService: DrawService) {} constructor(private drawService: DrawService) {}
......
...@@ -10,10 +10,11 @@ import { ...@@ -10,10 +10,11 @@ import {
import { FactionEntity } from '../faction/faction.entity'; import { FactionEntity } from '../faction/faction.entity';
import { Game_PersonEntity } from '../game/game.entity'; import { Game_PersonEntity } from '../game/game.entity';
import { NotificationModule } from 'src/notifications/notifications.module'; import { NotificationModule } from 'src/notifications/notifications.module';
/*
Draw /////////////////////////////////////////////////////////////////////
- contains everything to do with mapdrawing data. /// Draw ///
*/ /// - contains everything to do with mapdrawing data. ///
/////////////////////////////////////////////////////////////////////
@Module({ @Module({
imports: [ imports: [
TypeOrmModule.forFeature([ TypeOrmModule.forFeature([
......
...@@ -5,7 +5,6 @@ import { ...@@ -5,7 +5,6 @@ import {
OneToMany, OneToMany,
ManyToOne, ManyToOne,
OneToOne, OneToOne,
Timestamp,
JoinColumn, JoinColumn,
} from 'typeorm'; } from 'typeorm';
...@@ -15,7 +14,9 @@ import { MapDrawingEntity } from '../draw/coordinate.entity'; ...@@ -15,7 +14,9 @@ import { MapDrawingEntity } from '../draw/coordinate.entity';
import { Exclude } from 'class-transformer'; import { Exclude } from 'class-transformer';
import { ScoreEntity } from 'src/score/score.entity'; import { ScoreEntity } from 'src/score/score.entity';
//Faction, PowerUp, Faction_powerUp, FP_History, Score //////////////////////////////////////////////////////////////////////
/// Entities for Factions and Groups in Factions ///
//////////////////////////////////////////////////////////////////////
@Entity('Faction') @Entity('Faction')
export class FactionEntity { export class FactionEntity {
...@@ -24,12 +25,14 @@ export class FactionEntity { ...@@ -24,12 +25,14 @@ export class FactionEntity {
@Column({ type: 'float' }) multiplier: number; @Column({ type: 'float' }) multiplier: number;
@Column('text') colour: string; @Column('text') colour: string;
// Faction's password won't be included when FactionEntity is transformed
@Exclude() @Exclude()
@Column({ type: 'text' }) @Column({ type: 'text' })
factionPassword: string; factionPassword: string;
@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[];
// When Game where a Faction is in is deleted, the Factions in that game are also deleted
@ManyToOne(type => GameEntity, game => game.factions, { @ManyToOne(type => GameEntity, game => game.factions, {
onDelete: 'CASCADE', onDelete: 'CASCADE',
}) })
...@@ -51,49 +54,12 @@ export class FactionEntity { ...@@ -51,49 +54,12 @@ export class FactionEntity {
} }
} }
/* @Entity('PowerUp')
export class PowerUpEntity {
@PrimaryGeneratedColumn('uuid') powerUpId: string;
@Column({ type: 'text' }) powerUpName: string;
@Column({ type: 'text' }) powerUpDescription: string;
@Column({ type: 'int' }) amount: number;
@Column({ type: 'time' }) cooldown: string;
@OneToMany(type => FactionEntity, factions => factions.factionId, {
onDelete: 'CASCADE',
})
factions: Faction_PowerUpEntity[];
}
@Entity('Faction_PowerUp')
export class Faction_PowerUpEntity {
@PrimaryGeneratedColumn('uuid') faction_powerUpId: string;
@ManyToOne(type => FactionEntity, faction => faction.factionId)
faction: FactionEntity;
@ManyToOne(type => PowerUpEntity, powerUp => powerUp.factions)
powerUp: PowerUpEntity;
@OneToMany(type => FP_HistoryEntity, histories => histories.faction_PowerUp)
histories: FP_HistoryEntity[];
}
@Entity('FP_History')
export class FP_HistoryEntity {
@PrimaryGeneratedColumn('uuid') historyId: string;
@Column({ type: 'timestamp' }) historyTimeStamp: Timestamp;
@ManyToOne(
type => Faction_PowerUpEntity,
faction_PowerUp => faction_PowerUp.histories,
)
faction_PowerUp: Faction_PowerUpEntity;
} */
@Entity('GameGroup') @Entity('GameGroup')
export class GameGroupEntity { export class GameGroupEntity {
@PrimaryGeneratedColumn('uuid') id: string; @PrimaryGeneratedColumn('uuid') id: string;
@Column('text') name: string; @Column('text') name: string;
@Column('text') class: string; @Column('text') class: string;
// When Groups leader, players or Faction is deleted, the Group(s) go also
@OneToOne(type => Game_PersonEntity, person => person.leaderGroup, { @OneToOne(type => Game_PersonEntity, person => person.leaderGroup, {
onDelete: 'CASCADE', onDelete: 'CASCADE',
}) })
......
...@@ -6,6 +6,10 @@ import { FactionService } from './faction.service'; ...@@ -6,6 +6,10 @@ import { FactionService } from './faction.service';
import { GameGroupEntity, FactionEntity } from './faction.entity'; import { GameGroupEntity, FactionEntity } from './faction.entity';
import { Game_PersonEntity } from '../game/game.entity'; import { Game_PersonEntity } from '../game/game.entity';
/////////////////////////////////////////////////////////////////////
/// Faction ///
/// - contains everything to do with Faction data. ///
/////////////////////////////////////////////////////////////////////
@Module({ @Module({
imports: [ imports: [
TypeOrmModule.forFeature([ TypeOrmModule.forFeature([
......
...@@ -66,6 +66,7 @@ export class FactionService { ...@@ -66,6 +66,7 @@ export class FactionService {
}; };
} }
// changes factions multiplier to the value given to FactionDTO
async changeFactionMultiplier(body: FactionDTO) { async changeFactionMultiplier(body: FactionDTO) {
const faction = await this.factionRepository.findOne({ const faction = await this.factionRepository.findOne({
where: { factionId: body.factionId }, where: { factionId: body.factionId },
...@@ -129,6 +130,7 @@ export class FactionService { ...@@ -129,6 +130,7 @@ export class FactionService {
}; };
} }
// get the groups in the given Faction
async showGroups(factionId) { async showGroups(factionId) {
return await this.game_GroupRepository.find({ return await this.game_GroupRepository.find({
relations: ['leader', 'players'], relations: ['leader', 'players'],
...@@ -136,6 +138,7 @@ export class FactionService { ...@@ -136,6 +138,7 @@ export class FactionService {
}); });
} }
// puts a non admin or faction leader player into a specified group
async joinGroup(gameperson, data: JoinGameGroupDTO) { async joinGroup(gameperson, data: JoinGameGroupDTO) {
gameperson.group = data.groupId; gameperson.group = data.groupId;
await this.game_PersonRepository.save(gameperson); await this.game_PersonRepository.save(gameperson);
...@@ -144,6 +147,7 @@ export class FactionService { ...@@ -144,6 +147,7 @@ export class FactionService {
}; };
} }
// lists all members from given faction
async listFactionMembers(faction) { async listFactionMembers(faction) {
const members = await this.game_PersonRepository.find({ const members = await this.game_PersonRepository.find({
where: { faction }, where: { faction },
...@@ -155,6 +159,7 @@ export class FactionService { ...@@ -155,6 +159,7 @@ export class FactionService {
return members; return members;
} }
// checks if player is in a faction and what role the player is in
async verifyUser(person, game) { async verifyUser(person, game) {
const gameperson = await this.game_PersonRepository.findOne({ const gameperson = await this.game_PersonRepository.findOne({
where: { person, game }, where: { person, game },
......
...@@ -20,6 +20,15 @@ import { ValidationPipe } from '../shared/validation.pipe'; ...@@ -20,6 +20,15 @@ import { ValidationPipe } from '../shared/validation.pipe';
import { Roles, GameStates } from '../shared/guard.decorator'; import { Roles, GameStates } from '../shared/guard.decorator';
import { GameEntity } from './game.entity'; import { GameEntity } from './game.entity';
/////////////////////////////////////////////////////////////////////////
/// GameController ///
/// ///
/// Functions for creating, editing, deleting and listing games. ///
/// Also there are functions to get objective point info and list ///
/// of Factions in game ///
/// ///
/////////////////////////////////////////////////////////////////////////
@Controller('game') @Controller('game')
export class GameController { export class GameController {
constructor(private gameservice: GameService) {} constructor(private gameservice: GameService) {}
......
...@@ -56,6 +56,7 @@ export class GameEntity { ...@@ -56,6 +56,7 @@ 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;
// If a Faction or Game where the GamePerson was in is deleted, the GamePerson is also deleted
@ManyToOne(type => FactionEntity, faction => faction.game_persons, { @ManyToOne(type => FactionEntity, faction => faction.game_persons, {
onDelete: 'CASCADE', onDelete: 'CASCADE',
}) })
...@@ -68,6 +69,8 @@ export class Game_PersonEntity { ...@@ -68,6 +69,8 @@ export class Game_PersonEntity {
person: PersonEntity; person: PersonEntity;
@OneToOne(type => GameGroupEntity, group => group.leader) @OneToOne(type => GameGroupEntity, group => group.leader)
leaderGroup: GameGroupEntity; leaderGroup: GameGroupEntity;
// When a Group where GamePerson is is deleted, nothing happens to the GamePerson
@ManyToOne(type => GameGroupEntity, group => group.players, { @ManyToOne(type => GameGroupEntity, group => group.players, {
onDelete: 'NO ACTION', onDelete: 'NO ACTION',
}) })
...@@ -81,6 +84,7 @@ export class ObjectivePointEntity { ...@@ -81,6 +84,7 @@ export class ObjectivePointEntity {
@Column({ type: 'text' }) objectivePointDescription: string; @Column({ type: 'text' }) objectivePointDescription: string;
@Column({ type: 'float' }) objectivePointMultiplier: number; @Column({ type: 'float' }) objectivePointMultiplier: number;
// If the MapDrawing or Game where the ObjectivePoint was in is deleted, the ObjectivePoint is also deleted
@ManyToOne(type => MapDrawingEntity, coordinate => coordinate.data, { @ManyToOne(type => MapDrawingEntity, coordinate => coordinate.data, {
onDelete: 'CASCADE', onDelete: 'CASCADE',
}) })
...@@ -96,6 +100,9 @@ export class ObjectivePoint_HistoryEntity { ...@@ -96,6 +100,9 @@ export class ObjectivePoint_HistoryEntity {
@PrimaryGeneratedColumn('uuid') oP_HistoryId: string; @PrimaryGeneratedColumn('uuid') oP_HistoryId: string;
@Column({ type: 'timestamp' }) oP_HistoryTimestamp: Timestamp; @Column({ type: 'timestamp' }) oP_HistoryTimestamp: Timestamp;
@Column('float') action: number; @Column('float') action: number;
// If the owner Faction, capturer Faction or ObjectivePoint, that has, is trying to have or is the point where
// ObjectivePointHistory points to is deleted, the ObjectivePointHistory is also deleted
@ManyToOne(type => FactionEntity, factionEntity => factionEntity.factionId, { @ManyToOne(type => FactionEntity, factionEntity => factionEntity.factionId, {
onDelete: 'CASCADE', onDelete: 'CASCADE',
}) })
......
...@@ -17,6 +17,10 @@ import { TickService } from './tick.service'; ...@@ -17,6 +17,10 @@ import { TickService } from './tick.service';
import { ScoreService } from '../score/score.service'; import { ScoreService } from '../score/score.service';
import { ScoreEntity } from 'src/score/score.entity'; import { ScoreEntity } from 'src/score/score.entity';
/////////////////////////////////////////////////////////////////////
/// Game ///
/// - contains everything to do with Game data ///
/////////////////////////////////////////////////////////////////////
@Module({ @Module({
imports: [ imports: [
TypeOrmModule.forFeature([ TypeOrmModule.forFeature([
......
...@@ -16,6 +16,7 @@ export class NotificationEntity { ...@@ -16,6 +16,7 @@ export class NotificationEntity {
@Column({ type: 'text' }) message: string; @Column({ type: 'text' }) message: string;
@CreateDateColumn() issued: Date; @CreateDateColumn() issued: Date;
// Notifications are deleted if the game is deleted
@ManyToOne(type => GameEntity, game => game.id, { @ManyToOne(type => GameEntity, game => game.id, {
onDelete: 'CASCADE', onDelete: 'CASCADE',
}) })
......
...@@ -7,6 +7,10 @@ import { GameEntity } from '../game/game.entity'; ...@@ -7,6 +7,10 @@ import { GameEntity } from '../game/game.entity';
import { NotificationsController } from './notifications.controller'; import { NotificationsController } from './notifications.controller';
import { NotificationsService } from './notifications.service'; import { NotificationsService } from './notifications.service';
/////////////////////////////////////////////////////////////////////
/// Notification ///
/// - contains everything to do with Notification data. ///
/////////////////////////////////////////////////////////////////////
@Module({ @Module({
imports: [TypeOrmModule.forFeature([NotificationEntity, GameEntity])], imports: [TypeOrmModule.forFeature([NotificationEntity, GameEntity])],
providers: [NotificationGateway, NotificationsService], providers: [NotificationGateway, NotificationsService],
......
...@@ -10,6 +10,7 @@ export class NotificationsService { ...@@ -10,6 +10,7 @@ export class NotificationsService {
private notificationRepository: Repository<NotificationEntity>, private notificationRepository: Repository<NotificationEntity>,
) {} ) {}
// finds all notifications for specified game
async getNotifications(game: string) { async getNotifications(game: string) {
return this.notificationRepository.find({ game }); return this.notificationRepository.find({ game });
} }
......
...@@ -12,12 +12,14 @@ import { ReplayService } from './replay.service'; ...@@ -12,12 +12,14 @@ import { ReplayService } from './replay.service';
export class ReplayController { export class ReplayController {
constructor(private replayservice: ReplayService) {} constructor(private replayservice: ReplayService) {}
// gets replay data for specified Game
@Get(':id') @Get(':id')
@UseInterceptors(ClassSerializerInterceptor) @UseInterceptors(ClassSerializerInterceptor)
async replayInfo(@Param('id') gameId) { async replayInfo(@Param('id') gameId) {
return this.replayservice.replayData(gameId); return this.replayservice.replayData(gameId);
} }
// gets mockdata for specified Game
@Post('mockdata/:id') @Post('mockdata/:id')
async mockData(@Param('id') gameId) { async mockData(@Param('id') gameId) {
return this.replayservice.mockdata(gameId); return this.replayservice.mockdata(gameId);
......
...@@ -23,6 +23,10 @@ import { ScoreService } from '../score/score.service'; ...@@ -23,6 +23,10 @@ import { ScoreService } from '../score/score.service';
import { ScoreEntity } from '../score/score.entity'; import { ScoreEntity } from '../score/score.entity';
import { NotificationModule } from 'src/notifications/notifications.module'; import { NotificationModule } from 'src/notifications/notifications.module';
/////////////////////////////////////////////////////////////////////
/// Replay ///
/// - contains everything to do with Replay data. ///
/////////////////////////////////////////////////////////////////////
@Module({ @Module({
imports: [ imports: [
TypeOrmModule.forFeature([ TypeOrmModule.forFeature([
......
...@@ -41,6 +41,11 @@ export class ReplayService { ...@@ -41,6 +41,11 @@ export class ReplayService {
let mapDrawingIds = await this.mapdrawingRepository.find({ let mapDrawingIds = await this.mapdrawingRepository.find({
where: { gameId: gameId }, where: { gameId: gameId },
select: ['mapDrawingId'], select: ['mapDrawingId'],
// replay data for Factions
async replayData(gameId) {
const replay = await this.factionRepository.find({
where: { game: gameId },
relations: ['mapDrawings', 'scores', 'trackdata'],
}); });
let drawings = []; let drawings = [];
await Promise.all( await Promise.all(
......
...@@ -14,6 +14,7 @@ export class ScoreEntity { ...@@ -14,6 +14,7 @@ export class ScoreEntity {
@Column({ type: 'float' }) score: number; @Column({ type: 'float' }) score: number;
@Column({ type: 'float' }) scoreTimeStamp: number; @Column({ type: 'float' }) scoreTimeStamp: number;
// when Faction is deleted, it's Score is also deleted
@ManyToOne(type => FactionEntity, factionName => factionName.factionId, { @ManyToOne(type => FactionEntity, factionName => factionName.factionId, {
onDelete: 'CASCADE', onDelete: 'CASCADE',
}) })
......
...@@ -11,6 +11,10 @@ import { ...@@ -11,6 +11,10 @@ import {
import { ScoreEntity } from './score.entity'; import { ScoreEntity } from './score.entity';
import { NotificationModule } from '../notifications/notifications.module'; import { NotificationModule } from '../notifications/notifications.module';
/////////////////////////////////////////////////////////////////////
/// Score ///
/// - contains everything to do with Score data. ///
/////////////////////////////////////////////////////////////////////
@Module({ @Module({
imports: [ imports: [
TypeOrmModule.forFeature([ TypeOrmModule.forFeature([
......
...@@ -48,41 +48,4 @@ const grants = { ...@@ -48,41 +48,4 @@ const grants = {
//player & spectator //player & spectator
}; };
const ac = new AccessControl(grants); const ac = new AccessControl(grants);
\ No newline at end of file
/*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,7 +7,6 @@ import { ...@@ -7,7 +7,6 @@ import {
} from '@nestjs/common'; } from '@nestjs/common';
import { validate } from 'class-validator'; import { validate } from 'class-validator';
import { plainToClass } from 'class-transformer'; import { plainToClass } from 'class-transformer';
import { AdvancedConsoleLogger } from 'typeorm';
@Injectable() @Injectable()
export class ValidationPipe implements PipeTransform<any> { export class ValidationPipe implements PipeTransform<any> {
......
...@@ -16,6 +16,7 @@ export class TaskEntity { ...@@ -16,6 +16,7 @@ export class TaskEntity {
@Column({ type: 'text' }) taskDescription: string; @Column({ type: 'text' }) taskDescription: string;
@Column({ type: 'bool' }) taskIsActive: boolean; @Column({ type: 'bool' }) taskIsActive: boolean;
// when a Faction or Game is deleted, affiliated Tasks are also deleted
@ManyToOne(type => FactionEntity, faction => faction.factionId, { @ManyToOne(type => FactionEntity, faction => faction.factionId, {
onDelete: 'CASCADE', onDelete: 'CASCADE',
}) })
......
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