const UserError = require('vn-loopback/util/user-error'); module.exports = async function(app) { const models = app.models; models.VnRole.registerResolver('$subordinate', async(role, ctx) => { Object.assign(ctx, {req: {accessToken: {userId: ctx.accessToken.userId}}}); const isSubordinate = await models.Worker.isSubordinate(ctx, +ctx.modelId); if (!isSubordinate) throw new UserError(`You don't have enough privileges`); }); };