salix/modules/claim/back/methods/claim-state/isEditable.js

39 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-06-16 05:47:46 +00:00
module.exports = Self => {
Self.remoteMethodCtx('isEditable', {
2023-02-07 14:40:03 +00:00
description: 'Check if an state is editable',
2020-06-16 05:47:46 +00:00
accessType: 'READ',
accepts: [{
arg: 'id',
type: 'number',
required: true,
2023-02-07 14:40:03 +00:00
description: 'the st id',
2020-06-16 05:47:46 +00:00
http: {source: 'path'}
}],
returns: {
type: 'boolean',
root: true
},
http: {
path: `/:id/isEditable`,
verb: 'get'
}
});
Self.isEditable = async(ctx, id, options) => {
2020-06-16 05:47:46 +00:00
const userId = ctx.req.accessToken.userId;
2023-02-07 14:40:03 +00:00
const models = Self.app.models;
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
2023-02-07 14:40:03 +00:00
const state = await models.ClaimState.findById(id, {
include: {
relation: 'writeRole'
}
}, myOptions);
const roleWithGrants = state && state.writeRole().name;
return await models.Account.hasRole(userId, roleWithGrants, myOptions);
2020-06-16 05:47:46 +00:00
};
};