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 myUserId = ctx.req.accessToken.userId; let myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); const mySubordinates = await Self.mySubordinates(ctx, myOptions); const isSubordinate = mySubordinates.find(subordinate => { return subordinate.workerFk == id; }); const isHr = await models.Account.hasRole(myUserId, 'hr', myOptions); if (isHr || isSubordinate) return true; return false; }; };