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

40 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-05-17 11:27:51 +00:00
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'
}
});
2021-06-10 09:24:32 +00:00
Self.isSubordinate = async(ctx, id, options) => {
2019-05-17 11:27:51 +00:00
const models = Self.app.models;
const myOptions = {};
2021-06-10 09:24:32 +00:00
if (typeof options == 'object')
Object.assign(myOptions, options);
const mySubordinates = await Self.mySubordinates(ctx, myOptions);
2023-05-15 12:14:08 +00:00
const isSubordinate = mySubordinates.some(subordinate => subordinate.workerFk == id);
const forceIsSubordinate = await models.ACL.checkAccessAcl(ctx, 'Worker', 'forceIsSubordinate', 'READ');
2023-05-15 12:14:08 +00:00
return forceIsSubordinate || isSubordinate;
2019-05-17 11:27:51 +00:00
};
};