feat: refs #7182 optimize workerDms filter

This commit is contained in:
Alex Moreno 2024-09-11 08:16:21 +02:00
parent e7d3062208
commit 8dc83e2444
1 changed files with 54 additions and 3 deletions

View File

@ -57,15 +57,66 @@ module.exports = Self => {
}
}]
};
const where = mergeWhere(filter.where, yourOwnDms);
stmt.merge(conn.makeSuffix({where}));
const dmsIds = await conn.executeStmt(stmt);
const allowedIds = dmsIds.map(dms => dms.id);
const allowedFilter = mergeFilters(filter, {where: {dmsFk: {inq: allowedIds}}});
const allowedFilter = mergeFilters(filter, {where: {dmsFk: {inq: allowedIds}, workerFk: id}});
const find = await models.WorkerDms.find(allowedFilter);
const workerDms = await models.WorkerDms.find(allowedFilter);
return find;
const workerDocuware = filter.skip ? [] : await getDocuwareasync(ctx, id);
return workerDms.concat(workerDocuware);
async function getDocuwareasync(ctx, id) {
const {dmsTypeFk} = await models.Docuware.findOne({
fields: ['dmsTypeFk'],
where: {code: 'hr', action: 'find'}
});
if (!await models.DmsType.hasReadRole(ctx, dmsTypeFk)) return [];
let workerDocuware = [];
const worker = await models.Worker.findById(id, {fields: ['fi', 'firstName', 'lastName']});
const docuwareParse = {
'Filename': 'dmsFk',
'Tipo Documento': 'description',
'Stored on': 'created',
'Document ID': 'id',
'URL': 'download',
'Stored by': 'name',
'Estado': 'state'
};
workerDocuware =
await models.Docuware.getById('hr', worker.lastName + ' ' + worker.firstName, docuwareParse) ?? [];
const url = (await Self.app.models.Url.getUrl('docuware')) + 'WebClient';
for (document of workerDocuware) {
const docuwareId = document.id;
const defaultData = {
id: docuwareId,
workerFk: id,
dmsFk: docuwareId,
dms: {
id: docuwareId,
file: docuwareId + '.pdf',
isDocuware: true,
hasFile: false,
reference: worker.fi,
dmsFk: docuwareId,
url,
description: document.description + ' - ' + document.state,
download: document.download,
created: document.created,
dmsType: {name: 'Docuware'},
worker: {id: null, user: {name: document.name}},
}
};
Object.assign(document, defaultData);
}
return workerDocuware;
}
};
};