7182-workerDms_optimization #2946

Merged
alexm merged 7 commits from 7182-workerDms_optimization into dev 2024-09-12 07:28:08 +00:00
1 changed files with 0 additions and 74 deletions
Showing only changes of commit fbfbf21e06 - Show all commits

View File

@ -1,74 +0,0 @@
module.exports = Self => {
Self.remoteMethodCtx('filter', {
description: 'Find docuware documents',
accessType: 'READ',
accepts: [
{
arg: 'id',
type: 'number',
description: 'The worker id',
http: {source: 'path'}
}
],
returns: {
type: ['object'],
root: true
},
http: {
path: `/:id/filter`,
verb: 'GET'
}
});
Self.filter = async(ctx, id) => {
const models = Self.app.models;
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;
};