This commit is contained in:
parent
8dc83e2444
commit
fbfbf21e06
|
@ -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;
|
||||
};
|
Loading…
Reference in New Issue