From b651be99f3b7fd082b1f38a91649484397b68d48 Mon Sep 17 00:00:00 2001 From: Samuli Virtapohja <l4721@student.jamk.fi> Date: Wed, 24 Jul 2019 16:03:26 +0300 Subject: [PATCH] finishing audit --- src/app.module.ts | 7 ++----- src/faction/faction.service.ts | 4 ++++ src/shared/logging.interceptor.ts | 12 +++++++++--- src/task/task.controller.ts | 2 +- src/task/task.service.ts | 22 +++++++++++----------- 5 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/app.module.ts b/src/app.module.ts index 571d924..d3461d2 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -7,7 +7,7 @@ import { AppController } from './app.controller'; import { AppService } from './app.service'; import { RolesGuard } from './shared/roles.guard'; -import { LoggingInterceptor } from './shared/logging.interceptor'; +//import { LoggingInterceptor } from './shared/logging.interceptor'; import { StatesGuard } from './shared/states.guard'; import { HttpErrorFilter } from './shared/http-error.filter'; @@ -58,10 +58,7 @@ import { ReplayModule } from './replay/replay.module'; provide: APP_FILTER, useClass: HttpErrorFilter, }, - { - provide: APP_INTERCEPTOR, - useClass: LoggingInterceptor, - }, + { provide: APP_GUARD, useClass: RolesGuard, diff --git a/src/faction/faction.service.ts b/src/faction/faction.service.ts index a3ea83e..ba9370b 100644 --- a/src/faction/faction.service.ts +++ b/src/faction/faction.service.ts @@ -152,6 +152,10 @@ export class FactionService { relations: ['person', 'group'], }); + players.sort(function(a, b) { + return a.person.name.localeCompare(b.person.name); + }); + let groups = await this.game_GroupRepository.find({ where: { faction: factionId }, relations: ['leader', 'leader.person'], diff --git a/src/shared/logging.interceptor.ts b/src/shared/logging.interceptor.ts index 55083fa..c297174 100644 --- a/src/shared/logging.interceptor.ts +++ b/src/shared/logging.interceptor.ts @@ -1,7 +1,13 @@ -import { Injectable, NestInterceptor, ExecutionContext, CallHandler, Logger } from '@nestjs/common'; +import { + Injectable, + NestInterceptor, + ExecutionContext, + CallHandler, + Logger, +} from '@nestjs/common'; import { Observable } from 'rxjs'; import { tap } from 'rxjs/operators'; - +/* @Injectable() export class LoggingInterceptor implements NestInterceptor { intercept( @@ -19,4 +25,4 @@ export class LoggingInterceptor implements NestInterceptor { )) ) } -} \ No newline at end of file +}*/ diff --git a/src/task/task.controller.ts b/src/task/task.controller.ts index 14bbb21..ba9f6cc 100644 --- a/src/task/task.controller.ts +++ b/src/task/task.controller.ts @@ -42,7 +42,7 @@ export class TaskController { @Roles('admin') @UsePipes(new ValidationPipe()) async deleteTask(@Param('id') id: string, @Body() data: DeleteTaskDTO) { - return this.taskService.deleteTask(data); + return this.taskService.deleteTask(data, id); } // lists all the tasks for the game if the user has game_person entry diff --git a/src/task/task.service.ts b/src/task/task.service.ts index d09eb1c..0461d31 100644 --- a/src/task/task.service.ts +++ b/src/task/task.service.ts @@ -32,7 +32,7 @@ export class TaskService { await this.taskRepository.insert(createdTask); // notify subscribers about a new task // if faction was set it notifies only faction members, else everyone - await this.triggerTasks(task); + this.triggerTasks(task, task.taskGame); return { message: 'Task added', }; @@ -56,24 +56,17 @@ export class TaskService { task.taskWinner = data.taskWinner; task.taskIsActive = false; await this.taskRepository.save(task); - await this.triggerTasks(task); + this.triggerTasks(task, data.taskGame); return { message: 'Task updated and closed', }; } - private async triggerTasks(task) { - this.notificationGateway.server.emit( - task.faction != null ? task.faction.toString() : task.taskGame.toString(), - { type: 'task-update' }, - ); - } - - async deleteTask(data: DeleteTaskDTO) { + async deleteTask(data: DeleteTaskDTO, gameId) { const task = await this.taskRepository.findOne({ taskId: data.taskId }); if (task) { await this.taskRepository.delete({ taskId: task.taskId }); - await this.triggerTasks(task); + this.triggerTasks(task, gameId); return { message: 'Task deleted', }; @@ -81,6 +74,13 @@ export class TaskService { throw new HttpException('Task not found', HttpStatus.BAD_REQUEST); } + private triggerTasks(task, gameId) { + this.notificationGateway.server.emit(gameId, { + type: 'task-update', + message: task.faction != null ? task.faction.toString() : '', + }); + } + // finds all tasks if admin and if non-admin player it finds the playres own // tasks and general tasks async fetchTasks(gameperson, taskGame) { -- GitLab