dev #1731
|
@ -0,0 +1,3 @@
|
|||
UPDATE `vn`.`department`
|
||||
SET code='VN'
|
||||
WHERE name='VERDNATURA';
|
|
@ -29,24 +29,14 @@ module.exports = Self => {
|
|||
const models = Self.app.models;
|
||||
const conn = Self.dataSource.connector;
|
||||
|
||||
let allDepartments = [];
|
||||
if (departmentCodes) {
|
||||
const departments = await models.Department.find({
|
||||
fields: ['id'],
|
||||
fields: ['id', 'sons'],
|
||||
where: {code: {inq: departmentCodes}}
|
||||
});
|
||||
const departmentIds = departments.map(department => department.id);
|
||||
|
||||
let departmentLeaves = [];
|
||||
for (let id of departmentIds) {
|
||||
const leaves = await models.Department.getLeaves(ctx, id, null);
|
||||
console.log(leaves);
|
||||
for (let leave of leaves) departmentLeaves.push(leave.id);
|
||||
}
|
||||
|
||||
allDepartments = departmentIds.concat(departmentLeaves);
|
||||
console.log(allDepartments);
|
||||
const where = {'d.id': {inq: allDepartments}};
|
||||
const allLeaves = await getAllLeaves(ctx, departments);
|
||||
const where = {'d.id': {inq: allLeaves}};
|
||||
filter = mergeFilters(filter, {where});
|
||||
}
|
||||
|
||||
|
@ -60,4 +50,18 @@ module.exports = Self => {
|
|||
stmt.merge(conn.makeSuffix(filter));
|
||||
return conn.executeStmt(stmt);
|
||||
};
|
||||
|
||||
async function getAllLeaves(ctx, departments) {
|
||||
const models = Self.app.models;
|
||||
const leaves = [];
|
||||
for (const department of departments) {
|
||||
if (department.sons > 0) {
|
||||
const subLeaves = await models.Department.getLeaves(ctx, department.id, null);
|
||||
const grandLeaves = await getAllLeaves(ctx, subLeaves);
|
||||
leaves.push(...grandLeaves);
|
||||
}
|
||||
leaves.push(department.id);
|
||||
}
|
||||
return leaves;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue