Skip to content
Snippets Groups Projects
Commit 05626522 authored by L4072's avatar L4072
Browse files

More comments

parent ef08fa11
No related branches found
No related tags found
3 merge requests!59Development to master,!54Development to testing,!52Commenting to Development
Showing
with 57 additions and 55 deletions
......@@ -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([
......
......@@ -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([
......
......@@ -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 },
......
......@@ -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',
})
......
......@@ -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([
......
......@@ -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',
})
......
......@@ -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],
......
......@@ -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 });
}
......
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);
......
......@@ -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([
......
......@@ -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 },
......
......@@ -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',
})
......
......@@ -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([
......
......@@ -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
......@@ -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
......@@ -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> {
......
......@@ -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',
})
......
......@@ -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]),
......
......@@ -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({
......
......@@ -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')
......
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