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

42 lines
1.1 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) => {
const models = Self.app.models;
const myUserId = ctx.req.accessToken.userId;
const mySubordinates = await Self.mySubordinates(ctx);
const isSubordinate = mySubordinates.find(subordinate => {
return subordinate.workerFk == id;
});
const isHr = await models.Account.hasRole(myUserId, 'hr');
if (isHr || isSubordinate)
return true;
return false;
};
};