32 lines
911 B
JavaScript
32 lines
911 B
JavaScript
module.exports = Self => {
|
|
Self.remoteMethod('removes', {
|
|
description: 'Change the state of a ticket',
|
|
accessType: '',
|
|
accepts: [{
|
|
arg: 'params',
|
|
type: 'object',
|
|
required: true,
|
|
description: '[sales IDs], actualTicketFk',
|
|
http: {source: 'body'}
|
|
}],
|
|
returns: {
|
|
type: 'string',
|
|
root: true
|
|
},
|
|
http: {
|
|
path: `/removes`,
|
|
verb: 'post'
|
|
}
|
|
});
|
|
|
|
Self.removes = async params => {
|
|
let thisTicketIsEditable = await Self.app.models.Ticket.isEditable(params.actualTicketFk);
|
|
if (!thisTicketIsEditable)
|
|
throw new Error(`The sales of this ticket can't be modified`);
|
|
|
|
for (let i = 0; i < params.sales.length; i++) {
|
|
await Self.app.models.Sale.destroyById(params.sales[i].id);
|
|
}
|
|
};
|
|
};
|