2018-08-02 07:49:00 +00:00
|
|
|
const UserError = require('vn-loopback/common/helpers').UserError;
|
|
|
|
|
2018-05-17 11:29:18 +00:00
|
|
|
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'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-08-02 08:54:03 +00:00
|
|
|
Self.changeState = async params => {
|
2018-05-17 11:29:18 +00:00
|
|
|
let isEditable = await Self.app.models.Ticket.isEditable(params.ticketFk);
|
|
|
|
if (isEditable)
|
|
|
|
return await Self.app.models.TicketTracking.create(params);
|
|
|
|
|
2018-08-02 07:49:00 +00:00
|
|
|
throw new UserError(`You don't have enough privileges to change the state of this ticket`);
|
2018-05-17 11:29:18 +00:00
|
|
|
};
|
|
|
|
};
|