|
|
|
@ -15,8 +15,11 @@ import {
@@ -15,8 +15,11 @@ import {
|
|
|
|
|
USERS_SERVICE, |
|
|
|
|
} from 'src/core/consts' |
|
|
|
|
import { IPagination } from 'src/core/interfaces' |
|
|
|
|
import { TASKS_REPOSITORY } from 'src/domain/tasks/consts' |
|
|
|
|
import { ITasksRepository } from 'src/domain/tasks/interfaces' |
|
|
|
|
import { createUserName } from 'src/shared' |
|
|
|
|
import { getNewTaskNotificationHTML, getNewTaskNotificationText } from 'src/shared/templates' |
|
|
|
|
import { Brackets } from 'typeorm' |
|
|
|
|
import { |
|
|
|
|
CreateTaskDto, |
|
|
|
|
FilterTasksParamsDto, |
|
|
|
@ -43,6 +46,7 @@ export class AppTasksService {
@@ -43,6 +46,7 @@ export class AppTasksService {
|
|
|
|
|
private readonly tasksCommentsService: Tasks.ITasksCommentsService |
|
|
|
|
@Inject(MAILER_SERVICE) private readonly mailerService: Mailer.IMailerService |
|
|
|
|
@Inject(FACTORIES_SERVICE) private readonly factoriesService: Factories.IFactoriesService |
|
|
|
|
@Inject(TASKS_REPOSITORY) private readonly tasksRepository: ITasksRepository |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Метод для створення задач, створює окрему задачу для кожного з виконавців |
|
|
|
@ -252,20 +256,54 @@ export class AppTasksService {
@@ -252,20 +256,54 @@ export class AppTasksService {
|
|
|
|
|
|
|
|
|
|
const allPermittedUsersIds = [userId, ...permittedUsersIdsFromPermissions] |
|
|
|
|
|
|
|
|
|
if (dto.executorId) |
|
|
|
|
params.executorsIds = _.includes(allPermittedUsersIds, Number(dto.executorId)) |
|
|
|
|
? [dto.executorId] |
|
|
|
|
: [] |
|
|
|
|
else params.executorsIds = allPermittedUsersIds |
|
|
|
|
const allPermittedTasksIds = await this.getAllPermittedTasksIds( |
|
|
|
|
userId, |
|
|
|
|
allPermittedUsersIds, |
|
|
|
|
params.status, |
|
|
|
|
) |
|
|
|
|
params.includeIds = allPermittedTasksIds |
|
|
|
|
|
|
|
|
|
// if (dto.executorId) params.executorsIds = [dto.executorId]
|
|
|
|
|
// params.executorsIds = _.includes(allPermittedUsersIds, Number(dto.executorId))
|
|
|
|
|
// ? [dto.executorId]
|
|
|
|
|
// : []
|
|
|
|
|
// else params.executorsIds = allPermittedUsersIds
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (dto.executorId && role === Users.Role.Admin) params.executorsIds = [dto.executorId] |
|
|
|
|
if (dto.executorId) params.executorsIds = [dto.executorId] |
|
|
|
|
// if (dto.executorId && role === Users.Role.Admin) params.executorsIds = [dto.executorId]
|
|
|
|
|
|
|
|
|
|
if (dto.tasksIds) params.includeIds = dto.tasksIds |
|
|
|
|
|
|
|
|
|
return params |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private async getAllPermittedTasksIds( |
|
|
|
|
userId: number, |
|
|
|
|
executorsIds: number[], |
|
|
|
|
status?: Tasks.Status, |
|
|
|
|
) { |
|
|
|
|
const query = this.tasksRepository |
|
|
|
|
.createQueryBuilder('it') |
|
|
|
|
.where( |
|
|
|
|
new Brackets(subQuery => { |
|
|
|
|
subQuery |
|
|
|
|
.where('it.executorId = ANY(:executorsIds)', { |
|
|
|
|
executorsIds, |
|
|
|
|
}) |
|
|
|
|
.orWhere('it.initiatorId = :initiator', { |
|
|
|
|
initiator: userId, |
|
|
|
|
}) |
|
|
|
|
}), |
|
|
|
|
) |
|
|
|
|
.select('it.id') |
|
|
|
|
|
|
|
|
|
if (status) query.andWhere('it.status = :status', { status }) |
|
|
|
|
|
|
|
|
|
const tasks = await query.getMany() |
|
|
|
|
return tasks.map(it => it.id) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Метод для отримання списку власних задач користувача |
|
|
|
|
* @param {IPagination} pagination - параметри пагінації |
|
|
|
@ -474,7 +512,15 @@ export class AppTasksService {
@@ -474,7 +512,15 @@ export class AppTasksService {
|
|
|
|
|
|
|
|
|
|
const allPermittedUsersIds = [userId, ...permittedUsersIdsFromPermissions] |
|
|
|
|
|
|
|
|
|
params.executorsIds = allPermittedUsersIds |
|
|
|
|
const allPermittedTasksIds = await this.getAllPermittedTasksIds( |
|
|
|
|
userId, |
|
|
|
|
allPermittedUsersIds, |
|
|
|
|
params.status, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
params.includeIds = dto.ids |
|
|
|
|
? _.intersection(allPermittedTasksIds, dto.ids) |
|
|
|
|
: allPermittedTasksIds |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const { items } = await this.tasksService.getTasksList({ page: 1, limit: null }, params) |
|
|
|
|