From 0aed08e974bff09dc5437c58861d8a48ae5a6e71 Mon Sep 17 00:00:00 2001 From: L4168 <L4168@student.jamk.fi> Date: Thu, 27 Jun 2019 14:51:12 +0300 Subject: [PATCH] fetchTasks returns active and associated taks --- src/task/task.service.ts | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/task/task.service.ts b/src/task/task.service.ts index 9d4fe9a..082f5b0 100644 --- a/src/task/task.service.ts +++ b/src/task/task.service.ts @@ -32,7 +32,6 @@ export class TaskService { throw new HttpException('Faction not found', HttpStatus.BAD_REQUEST); } const createdTask = await this.taskRepository.create(task); - console.log(createdTask); await this.taskRepository.insert(createdTask); // notify subscribers about a new task // if faction was set it notifies only faction members, else everyone @@ -70,11 +69,31 @@ export class TaskService { } async fetchTasks(user, taskGame) { - // to do: limit fetch for factions const gamePerson = await this.gamePersonRepository.findOne({ - person: user, - game: taskGame, + where: { + person: user, + game: taskGame, + }, + relations: ['faction'], }); - return await this.taskRepository.find({ taskGame: taskGame }); + if (gamePerson.role == 'admin') { + return await this.taskRepository.find({ taskGame: taskGame }); + } else { + return await this.taskRepository.find({ + relations: ['faction'], + where: [ + { + taskGame: taskGame, + faction: gamePerson.faction.factionId, + taskIsActive: true, + }, + { + taskGame: taskGame, + faction: null, + taskIsActive: true, + }, + ], + }); + } } } -- GitLab