39 lines
991 B
JavaScript
39 lines
991 B
JavaScript
module.exports = Self => {
|
|
Self.remoteMethod('canCreateTicket', {
|
|
description: 'Checks if the client is active',
|
|
accessType: 'READ',
|
|
accepts: [
|
|
{
|
|
arg: 'id',
|
|
type: 'string',
|
|
required: true,
|
|
description: 'The user id',
|
|
http: {source: 'path'}
|
|
}],
|
|
returns: {
|
|
type: 'boolean',
|
|
root: true
|
|
},
|
|
http: {
|
|
path: `/:id/canCreateTicket`,
|
|
verb: 'GET'
|
|
}
|
|
});
|
|
|
|
Self.canCreateTicket = async(id, options) => {
|
|
const models = Self.app.models;
|
|
const myOptions = {};
|
|
|
|
if (typeof options == 'object')
|
|
Object.assign(myOptions, options);
|
|
|
|
const client = await models.Client.findById(id, null, myOptions);
|
|
|
|
const canCreateTicket = client && client.isActive;
|
|
if (!canCreateTicket)
|
|
return false;
|
|
|
|
return true;
|
|
};
|
|
};
|