salix/modules/worker/back/methods/worker/isSubordinate.js

40 lines
1.2 KiB
JavaScript

module.exports = Self => {
Self.remoteMethod('isSubordinate', {
description: 'Check if an employee is subordinate',
accessType: 'READ',
accepts: [{
arg: 'ctx',
type: 'Object',
http: {source: 'context'}
}, {
arg: 'id',
type: 'number',
required: true,
description: 'The worker id',
http: {source: 'path'}
}],
returns: {
type: 'boolean',
root: true
},
http: {
path: `/:id/isSubordinate`,
verb: 'GET'
}
});
Self.isSubordinate = async(ctx, id, options) => {
const models = Self.app.models;
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const mySubordinates = await Self.mySubordinates(ctx, myOptions);
const isSubordinate = mySubordinates.some(subordinate => subordinate.workerFk == id);
const forceIsSubordinate = await models.ACL.checkAccessAcl(ctx, 'Worker', 'forceIsSubordinate', 'READ');
return forceIsSubordinate || isSubordinate;
};
};