dev #1731

Merged
jgallego merged 105 commits from dev into test 2023-08-31 09:13:29 +00:00
2 changed files with 20 additions and 13 deletions
Showing only changes of commit e9ef81f8d7 - Show all commits

View File

@ -0,0 +1,3 @@
UPDATE `vn`.`department`
SET code='VN'
WHERE name='VERDNATURA';

View File

@ -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;
}
};