33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
module.exports = Self => {
|
|
Self.remoteMethodCtx('isRoleAdvanced', {
|
|
description: 'Check if a ticket is editable',
|
|
accessType: 'READ',
|
|
returns: {
|
|
type: 'boolean',
|
|
root: true
|
|
},
|
|
http: {
|
|
path: `/isRoleAdvanced`,
|
|
verb: 'GET'
|
|
}
|
|
});
|
|
|
|
Self.isRoleAdvanced = async(ctx, options) => {
|
|
const models = Self.app.models;
|
|
const userId = ctx.req.accessToken.userId;
|
|
const myOptions = {};
|
|
|
|
if (typeof options == 'object')
|
|
Object.assign(myOptions, options);
|
|
|
|
const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant', myOptions);
|
|
const isDeliveryBoss = await models.Account.hasRole(userId, 'deliveryBoss', myOptions);
|
|
const isBuyer = await models.Account.hasRole(userId, 'buyer', myOptions);
|
|
const isClaimManager = await models.Account.hasRole(userId, 'claimManager', myOptions);
|
|
|
|
const isRoleAdvanced = isSalesAssistant || isDeliveryBoss || isBuyer || isClaimManager;
|
|
|
|
return isRoleAdvanced;
|
|
};
|
|
};
|