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

32 lines
909 B
JavaScript
Raw Normal View History

const UserError = require('vn-loopback/common/helpers').UserError;
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 => {
let isEditable = await Self.app.models.Ticket.isEditable(params.ticketFk);
if (isEditable)
return await Self.app.models.TicketTracking.create(params);
throw new UserError(`You don't have enough privileges to change the state of this ticket`);
};
};