diff --git a/src/task/task.service.ts b/src/task/task.service.ts index 9d4fe9a2b34f31aee891ff457f53db286a2982d2..082f5b00f6203ca0558c88423d8a7e6da99fe7eb 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, + }, + ], + }); + } } }