From 05626522c365d32e5242d6d4a29868afdbd207b2 Mon Sep 17 00:00:00 2001 From: Marko <L4072@student.jamk.fi> Date: Wed, 17 Jul 2019 23:34:12 +0300 Subject: [PATCH] More comments --- src/draw/draw.module.ts | 9 ++--- src/faction/faction.module.ts | 5 ++- src/faction/faction.service.ts | 4 +++ src/game/game.entity.ts | 7 ++++ src/game/game.module.ts | 4 +++ src/notifications/notification.entity.ts | 1 + src/notifications/notifications.module.ts | 4 +++ src/notifications/notifications.service.ts | 1 + src/replay/replay.controller.ts | 4 ++- src/replay/replay.module.ts | 4 +++ src/replay/replay.service.ts | 1 + src/score/score.entity.ts | 1 + src/score/score.module.ts | 4 +++ src/score/score.service.ts | 8 +---- src/shared/roles.controller.ts | 39 +--------------------- src/shared/validation.pipe.ts | 1 - src/task/task.entity.ts | 1 + src/task/task.module.ts | 4 +++ src/task/task.service.ts | 3 +- src/tracking/tracking.controller.ts | 7 ++-- src/tracking/tracking.dto.ts | 1 - src/tracking/tracking.entity.ts | 1 + src/tracking/tracking.module.ts | 4 +++ 23 files changed, 62 insertions(+), 56 deletions(-) diff --git a/src/draw/draw.module.ts b/src/draw/draw.module.ts index 86bb2e0..bea1b66 100644 --- a/src/draw/draw.module.ts +++ b/src/draw/draw.module.ts @@ -10,10 +10,11 @@ import { import { FactionEntity } from '../faction/faction.entity'; import { Game_PersonEntity } from '../game/game.entity'; import { NotificationModule } from 'src/notifications/notifications.module'; -/* -Draw -- contains everything to do with mapdrawing data. -*/ + +///////////////////////////////////////////////////////////////////// +/// Draw /// +/// - contains everything to do with mapdrawing data. /// +///////////////////////////////////////////////////////////////////// @Module({ imports: [ TypeOrmModule.forFeature([ diff --git a/src/faction/faction.module.ts b/src/faction/faction.module.ts index 3955479..f53f076 100644 --- a/src/faction/faction.module.ts +++ b/src/faction/faction.module.ts @@ -6,7 +6,10 @@ import { FactionService } from './faction.service'; import { GameGroupEntity, FactionEntity } from './faction.entity'; import { Game_PersonEntity } from '../game/game.entity'; -// Contains everything to do with Faction data. +///////////////////////////////////////////////////////////////////// +/// Faction /// +/// - contains everything to do with Faction data. /// +///////////////////////////////////////////////////////////////////// @Module({ imports: [ TypeOrmModule.forFeature([ diff --git a/src/faction/faction.service.ts b/src/faction/faction.service.ts index 936786f..203e1f4 100644 --- a/src/faction/faction.service.ts +++ b/src/faction/faction.service.ts @@ -131,6 +131,7 @@ export class FactionService { }; } + // get the groups in the given Faction async showGroups(factionId) { return await this.game_GroupRepository.find({ relations: ['leader', 'players'], @@ -138,6 +139,7 @@ export class FactionService { }); } + // puts a non admin or faction leader player into a specified group async joinGroup(gameperson, data: JoinGameGroupDTO) { gameperson.group = data.groupId; await this.game_PersonRepository.save(gameperson); @@ -146,6 +148,7 @@ export class FactionService { }; } + // lists all members from given faction async listFactionMembers(faction) { const members = await this.game_PersonRepository.find({ where: { faction }, @@ -157,6 +160,7 @@ export class FactionService { return members; } + // checks if player is in a faction and what role the player is in async verifyUser(person, game) { const gameperson = await this.game_PersonRepository.findOne({ where: { person, game }, diff --git a/src/game/game.entity.ts b/src/game/game.entity.ts index 7ae6e29..22e171b 100644 --- a/src/game/game.entity.ts +++ b/src/game/game.entity.ts @@ -56,6 +56,7 @@ export class GameEntity { export class Game_PersonEntity { @PrimaryGeneratedColumn('uuid') gamepersonId: 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, { onDelete: 'CASCADE', }) @@ -68,6 +69,8 @@ export class Game_PersonEntity { person: PersonEntity; @OneToOne(type => GameGroupEntity, group => group.leader) leaderGroup: GameGroupEntity; + + // When a Group where GamePerson is is deleted, nothing happens to the GamePerson @ManyToOne(type => GameGroupEntity, group => group.players, { onDelete: 'NO ACTION', }) @@ -81,6 +84,7 @@ export class ObjectivePointEntity { @Column({ type: 'text' }) objectivePointDescription: string; @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, { onDelete: 'CASCADE', }) @@ -96,6 +100,9 @@ export class ObjectivePoint_HistoryEntity { @PrimaryGeneratedColumn('uuid') oP_HistoryId: string; @Column({ type: 'timestamp' }) oP_HistoryTimestamp: Timestamp; @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, { onDelete: 'CASCADE', }) diff --git a/src/game/game.module.ts b/src/game/game.module.ts index 1c9e86f..b789d8b 100644 --- a/src/game/game.module.ts +++ b/src/game/game.module.ts @@ -14,6 +14,10 @@ import { GameGroupEntity } from '../faction/faction.entity'; import { FactionEntity } from '../faction/faction.entity'; import { NotificationModule } from '../notifications/notifications.module'; +///////////////////////////////////////////////////////////////////// +/// Game /// +/// - contains everything to do with Game data /// +///////////////////////////////////////////////////////////////////// @Module({ imports: [ TypeOrmModule.forFeature([ diff --git a/src/notifications/notification.entity.ts b/src/notifications/notification.entity.ts index f9d5dca..5e1f841 100644 --- a/src/notifications/notification.entity.ts +++ b/src/notifications/notification.entity.ts @@ -16,6 +16,7 @@ export class NotificationEntity { @Column({ type: 'text' }) message: string; @CreateDateColumn() issued: Date; + // Notifications are deleted if the game is deleted @ManyToOne(type => GameEntity, game => game.id, { onDelete: 'CASCADE', }) diff --git a/src/notifications/notifications.module.ts b/src/notifications/notifications.module.ts index 607ea0c..6133784 100644 --- a/src/notifications/notifications.module.ts +++ b/src/notifications/notifications.module.ts @@ -7,6 +7,10 @@ import { GameEntity } from '../game/game.entity'; import { NotificationsController } from './notifications.controller'; import { NotificationsService } from './notifications.service'; +///////////////////////////////////////////////////////////////////// +/// Notification /// +/// - contains everything to do with Notification data. /// +///////////////////////////////////////////////////////////////////// @Module({ imports: [TypeOrmModule.forFeature([NotificationEntity, GameEntity])], providers: [NotificationGateway, NotificationsService], diff --git a/src/notifications/notifications.service.ts b/src/notifications/notifications.service.ts index d63f017..0bbe016 100644 --- a/src/notifications/notifications.service.ts +++ b/src/notifications/notifications.service.ts @@ -10,6 +10,7 @@ export class NotificationsService { private notificationRepository: Repository<NotificationEntity>, ) {} + // finds all notifications for specified game async getNotifications(game: string) { return this.notificationRepository.find({ game }); } diff --git a/src/replay/replay.controller.ts b/src/replay/replay.controller.ts index acc2ef5..17f7d50 100644 --- a/src/replay/replay.controller.ts +++ b/src/replay/replay.controller.ts @@ -1,21 +1,23 @@ import { Controller, Get, Param, Post } from '@nestjs/common'; import { ReplayService } from './replay.service'; -import { Roles } from 'src/shared/guard.decorator'; @Controller('replay') export class ReplayController { constructor(private replayservice: ReplayService) {} + // gets replay data for specified Game @Get(':id') async replayInfo(@Param('id') gameId) { return this.replayservice.replayData(gameId); } + // gets mockdata for specified Game @Post('mockdata/:id') async mockData(@Param('id') gameId) { return this.replayservice.mockdata(gameId); } + // gets players for specified game @Get('players/:id') async getPlayers(@Param('id') gameId) { return this.replayservice.getPlayers(gameId); diff --git a/src/replay/replay.module.ts b/src/replay/replay.module.ts index c7accef..d39bbb8 100644 --- a/src/replay/replay.module.ts +++ b/src/replay/replay.module.ts @@ -11,6 +11,10 @@ import { TrackingService } from '../tracking/tracking.service'; import { TrackingEntity } from 'src/tracking/tracking.entity'; import { PersonEntity } from 'src/user/user.entity'; +///////////////////////////////////////////////////////////////////// +/// Replay /// +/// - contains everything to do with Replay data. /// +///////////////////////////////////////////////////////////////////// @Module({ imports: [ TypeOrmModule.forFeature([ diff --git a/src/replay/replay.service.ts b/src/replay/replay.service.ts index f543086..b027922 100644 --- a/src/replay/replay.service.ts +++ b/src/replay/replay.service.ts @@ -24,6 +24,7 @@ export class ReplayService { private factionService: FactionService, ) {} + // replay data for Factions async replayData(gameId) { const replay = await this.factionRepository.find({ where: { game: gameId }, diff --git a/src/score/score.entity.ts b/src/score/score.entity.ts index 6ca9ab7..5b2674f 100644 --- a/src/score/score.entity.ts +++ b/src/score/score.entity.ts @@ -14,6 +14,7 @@ export class ScoreEntity { @Column({ type: 'float' }) score: number; @CreateDateColumn({ type: 'timestamp' }) scoreTimeStamp: Timestamp; + // when Faction is deleted, it's Score is also deleted @ManyToOne(type => FactionEntity, factionName => factionName.factionId, { onDelete: 'CASCADE', }) diff --git a/src/score/score.module.ts b/src/score/score.module.ts index c04486f..fce21d1 100644 --- a/src/score/score.module.ts +++ b/src/score/score.module.ts @@ -11,6 +11,10 @@ import { import { ScoreEntity } from './score.entity'; import { NotificationModule } from '../notifications/notifications.module'; +///////////////////////////////////////////////////////////////////// +/// Score /// +/// - contains everything to do with Score data. /// +///////////////////////////////////////////////////////////////////// @Module({ imports: [ TypeOrmModule.forFeature([ diff --git a/src/score/score.service.ts b/src/score/score.service.ts index 640970c..56e69b1 100644 --- a/src/score/score.service.ts +++ b/src/score/score.service.ts @@ -109,10 +109,4 @@ export class ScoreService { ); return scores; } -} // - -// Hae kaikki Objective pointit -// aja map funktio pelin objective pointteihin -// jokaisella objective point ID:llä hae historystä -// relaatio, missä uusin timestamp -// katso uusimmista history entrystä omistaja +} \ No newline at end of file diff --git a/src/shared/roles.controller.ts b/src/shared/roles.controller.ts index 0d91e06..0298723 100644 --- a/src/shared/roles.controller.ts +++ b/src/shared/roles.controller.ts @@ -48,41 +48,4 @@ const grants = { //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(); - } -});*/ +const ac = new AccessControl(grants); \ No newline at end of file diff --git a/src/shared/validation.pipe.ts b/src/shared/validation.pipe.ts index cff51f1..423f231 100644 --- a/src/shared/validation.pipe.ts +++ b/src/shared/validation.pipe.ts @@ -7,7 +7,6 @@ import { } from '@nestjs/common'; import { validate } from 'class-validator'; import { plainToClass } from 'class-transformer'; -import { AdvancedConsoleLogger } from 'typeorm'; @Injectable() export class ValidationPipe implements PipeTransform<any> { diff --git a/src/task/task.entity.ts b/src/task/task.entity.ts index f1c1cf1..762dbc0 100644 --- a/src/task/task.entity.ts +++ b/src/task/task.entity.ts @@ -16,6 +16,7 @@ export class TaskEntity { @Column({ type: 'text' }) taskDescription: string; @Column({ type: 'bool' }) taskIsActive: boolean; + // when a Faction or Game is deleted, affiliated Tasks are also deleted @ManyToOne(type => FactionEntity, faction => faction.factionId, { onDelete: 'CASCADE', }) diff --git a/src/task/task.module.ts b/src/task/task.module.ts index 2391f28..dc4b8f6 100644 --- a/src/task/task.module.ts +++ b/src/task/task.module.ts @@ -7,6 +7,10 @@ import { TaskEntity } from './task.entity'; import { FactionEntity } from '../faction/faction.entity'; import { NotificationModule } from '../notifications/notifications.module'; +///////////////////////////////////////////////////////////////////// +/// Task /// +/// - contains everything to do with Task data. /// +///////////////////////////////////////////////////////////////////// @Module({ imports: [ TypeOrmModule.forFeature([TaskEntity, FactionEntity]), diff --git a/src/task/task.service.ts b/src/task/task.service.ts index 043f65a..478a6c1 100644 --- a/src/task/task.service.ts +++ b/src/task/task.service.ts @@ -5,7 +5,6 @@ import { InjectRepository } from '@nestjs/typeorm'; import { TaskEntity } from './task.entity'; import { CreateTaskDTO, EditTaskDTO, DeleteTaskDTO } from './task.dto'; import { FactionEntity } from '../faction/faction.entity'; -import { Game_PersonEntity } from '../game/game.entity'; import { NotificationGateway } from '../notifications/notifications.gateway'; @Injectable() @@ -76,6 +75,8 @@ export class TaskService { throw new HttpException('Task not found', HttpStatus.BAD_REQUEST); } + // finds all tasks if admin and if non-admin player it finds the playres own + // tasks and general tasks async fetchTasks(gameperson, taskGame) { if (gameperson.role == 'admin') { return await this.taskRepository.find({ diff --git a/src/tracking/tracking.controller.ts b/src/tracking/tracking.controller.ts index 2b409ce..93d0779 100644 --- a/src/tracking/tracking.controller.ts +++ b/src/tracking/tracking.controller.ts @@ -2,7 +2,6 @@ import { Controller, Post, Param, - UseGuards, UsePipes, Body, Get, @@ -15,7 +14,7 @@ import { User } from '../user/user.decorator'; import { Roles, GameStates } from '../shared/guard.decorator'; import { ValidationPipe } from '../shared/validation.pipe'; import { GeoDTO } from './geo.dto'; -import { GamePerson } from 'src/game/gameperson.decorator'; +import { GamePerson } from '../game/gameperson.decorator'; @Controller('tracking') export class TrackingController { @@ -35,6 +34,8 @@ export class TrackingController { return this.trackingservice.trackLocation(gameperson, id, trackdata); } + // finds certain player's location + // :id is the id of the game @Get('players/:id') @Roles('admin', 'factionleader') @GameStates('STARTED', 'PAUSED') @@ -42,6 +43,8 @@ export class TrackingController { return this.trackingservice.getPlayers(gameperson, gameId); } + + // finds certain player @Get('player/:id') @Roles('admin', 'factionleader') @GameStates('STARTED', 'PAUSED') diff --git a/src/tracking/tracking.dto.ts b/src/tracking/tracking.dto.ts index 81cc715..3ac93c7 100644 --- a/src/tracking/tracking.dto.ts +++ b/src/tracking/tracking.dto.ts @@ -1,4 +1,3 @@ -import { Game_PersonEntity } from '../game/game.entity'; import { Allow, ValidateNested } from 'class-validator'; import { GeoDTO } from './geo.dto'; import { Type } from 'class-transformer'; diff --git a/src/tracking/tracking.entity.ts b/src/tracking/tracking.entity.ts index 8c5b9ab..4952e18 100644 --- a/src/tracking/tracking.entity.ts +++ b/src/tracking/tracking.entity.ts @@ -9,6 +9,7 @@ export class TrackingEntity { @Column({ type: 'json', nullable: true }) data: GeoDTO[]; @Column('text') icon: string; + // when the GamePerson is deleted it's tracking data is also deleted @ManyToOne(type => Game_PersonEntity, person => person.gamepersonId, { onDelete: 'CASCADE', }) diff --git a/src/tracking/tracking.module.ts b/src/tracking/tracking.module.ts index fe31de3..b2a7312 100644 --- a/src/tracking/tracking.module.ts +++ b/src/tracking/tracking.module.ts @@ -7,6 +7,10 @@ import { TrackingEntity } from './tracking.entity'; import { Game_PersonEntity } from '../game/game.entity'; import { PersonEntity } from '../user/user.entity'; +///////////////////////////////////////////////////////////////////// +/// Tracking /// +/// - contains everything to do with Tracking data. /// +///////////////////////////////////////////////////////////////////// @Module({ imports: [ TypeOrmModule.forFeature([TrackingEntity, Game_PersonEntity, PersonEntity]), -- GitLab