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'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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 => {
|
2020-01-02 10:21:11 +00:00
|
|
|
return subordinate.workerFk == id;
|
2019-05-17 11:27:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const isHr = await models.Account.hasRole(myUserId, 'hr');
|
|
|
|
if (isHr || isSubordinate)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
};
|