salix/services/ticket/common/methods/ticket-tracking/changeState.js

30 lines
844 B
JavaScript

module.exports = Self => {
Self.remoteMethod('changeState', {
description: 'Change the state of a ticket',
accessType: 'WRITE',
accepts: [{
arg: 'params',
type: 'object',
required: true,
description: 'ticketFk',
http: {source: 'body'}
}],
returns: {
type: 'string',
root: true
},
http: {
path: `/changeState`,
verb: 'post'
}
});
Self.changeState = async (params, ctx) => {
let isEditable = await Self.app.models.Ticket.isEditable(params.ticketFk);
if (isEditable)
return await Self.app.models.TicketTracking.create(params);
throw new Error(`You don't have enough privileges to change the state of this ticket`);
};
};