Merge pull request '7182-workerDms_optimization' (!2946) from 7182-workerDms_optimization into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #2946 Reviewed-by: Jorge Penadés <jorgep@verdnatura.es>
This commit is contained in:
commit
9435ce8c5b
|
@ -8,19 +8,19 @@ module.exports = Self => {
|
||||||
accepts: [
|
accepts: [
|
||||||
{
|
{
|
||||||
arg: 'id',
|
arg: 'id',
|
||||||
type: 'Number',
|
type: 'number',
|
||||||
description: 'The worker id',
|
description: 'The worker id',
|
||||||
http: {source: 'path'}
|
http: {source: 'path'}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'filter',
|
arg: 'filter',
|
||||||
type: 'Object',
|
type: 'object',
|
||||||
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
|
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
|
||||||
http: {source: 'query'}
|
http: {source: 'query'}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
returns: {
|
returns: {
|
||||||
type: ['Object'],
|
type: ['object'],
|
||||||
root: true
|
root: true
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
|
@ -36,6 +36,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
// Get ids alloweds
|
// Get ids alloweds
|
||||||
const account = await models.VnUser.findById(userId);
|
const account = await models.VnUser.findById(userId);
|
||||||
|
|
||||||
const stmt = new ParameterizedSQL(
|
const stmt = new ParameterizedSQL(
|
||||||
`SELECT d.id, d.id dmsFk
|
`SELECT d.id, d.id dmsFk
|
||||||
FROM workerDms wd
|
FROM workerDms wd
|
||||||
|
@ -45,30 +46,40 @@ module.exports = Self => {
|
||||||
AND rr.role = ?
|
AND rr.role = ?
|
||||||
`, [account.roleFk]
|
`, [account.roleFk]
|
||||||
);
|
);
|
||||||
const yourOwnDms = {and: [{isReadableByWorker: true}, {worker: userId}]};
|
const yourOwnDms = {
|
||||||
const where = {
|
or: [
|
||||||
or: [yourOwnDms, {
|
{and: [
|
||||||
|
{isReadableByWorker: true},
|
||||||
|
{worker: userId}
|
||||||
|
]},
|
||||||
|
{
|
||||||
role: {
|
role: {
|
||||||
neq: null
|
neq: null
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
stmt.merge(conn.makeSuffix(mergeWhere(filter.where, where)));
|
|
||||||
|
|
||||||
// Get workerDms alloweds
|
const where = mergeWhere(filter.where, yourOwnDms);
|
||||||
|
stmt.merge(conn.makeSuffix({where}));
|
||||||
const dmsIds = await conn.executeStmt(stmt);
|
const dmsIds = await conn.executeStmt(stmt);
|
||||||
|
|
||||||
const allowedIds = dmsIds.map(dms => dms.id);
|
const allowedIds = dmsIds.map(dms => dms.id);
|
||||||
const allowedFilter = mergeFilters(filter, {where: {dmsFk: {inq: allowedIds}, workerFk: id}});
|
const allowedFilter = mergeFilters(filter, {where: {dmsFk: {inq: allowedIds}, workerFk: id}});
|
||||||
let workerDms = await models.WorkerDms.find(allowedFilter);
|
|
||||||
|
|
||||||
// Get docuware info
|
const workerDms = await models.WorkerDms.find(allowedFilter);
|
||||||
const docuware = await models.Docuware.findOne({
|
|
||||||
|
const workerDocuware = filter.skip ? [] : await getDocuware(ctx, id);
|
||||||
|
return workerDms.concat(workerDocuware);
|
||||||
|
|
||||||
|
async function getDocuware(ctx, id) {
|
||||||
|
const {dmsTypeFk} = await models.Docuware.findOne({
|
||||||
fields: ['dmsTypeFk'],
|
fields: ['dmsTypeFk'],
|
||||||
where: {code: 'hr', action: 'find'}
|
where: {code: 'hr', action: 'find'}
|
||||||
});
|
});
|
||||||
const docuwareDmsType = docuware.dmsTypeFk;
|
|
||||||
|
if (!await models.DmsType.hasReadRole(ctx, dmsTypeFk)) return [];
|
||||||
|
|
||||||
let workerDocuware = [];
|
let workerDocuware = [];
|
||||||
if (!filter.skip && (!docuwareDmsType || (docuwareDmsType && await models.DmsType.hasReadRole(ctx, docuwareDmsType)))) {
|
|
||||||
const worker = await models.Worker.findById(id, {fields: ['fi', 'firstName', 'lastName']});
|
const worker = await models.Worker.findById(id, {fields: ['fi', 'firstName', 'lastName']});
|
||||||
const docuwareParse = {
|
const docuwareParse = {
|
||||||
'Filename': 'dmsFk',
|
'Filename': 'dmsFk',
|
||||||
|
@ -106,7 +117,7 @@ module.exports = Self => {
|
||||||
};
|
};
|
||||||
Object.assign(document, defaultData);
|
Object.assign(document, defaultData);
|
||||||
}
|
}
|
||||||
|
return workerDocuware;
|
||||||
}
|
}
|
||||||
return workerDms.concat(workerDocuware);
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue