Files

27 lines
895 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Op } from 'sequelize';
import { models } from '../models/index.js';
import { AppErrorInvalid, SystemError } from './errors.js';
export async function assignmentCases(caseIds, transaction) {
const tasks = await models.Case.findAll({
where: { id: caseIds },
order: [['id', 'ASC']],
lock: transaction.LOCK.UPDATE,
transaction,
});
if (tasks.length !== caseIds.length) throw new AppErrorInvalid('caseIds');
return tasks;
}
export async function assertTechnicalAvailable(user, tasks, transaction) {
if (user.role !== 'technical') return;
for (const task of tasks) {
const assigned = await task.getUsers({
where: { role: 'technical', id: { [Op.ne]: user.id } },
lock: transaction.LOCK.UPDATE,
transaction,
});
if (assigned.length) throw new SystemError(409, `В кейсе «${task.name}» уже назначен технический эксперт.`);
}
}