salix/modules/ticket/back/methods/sale/reserve.js

34 lines
994 B
JavaScript
Raw Normal View History

2018-12-27 11:54:16 +00:00
let UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethod('reserve', {
description: 'Change the state of a ticket',
2019-05-22 10:35:24 +00:00
accessType: 'WRITE',
accepts: [{
arg: 'params',
type: 'object',
required: true,
description: '[sales IDs], ticketFk, reserved',
http: {source: 'body'}
}],
returns: {
type: 'string',
root: true
},
http: {
path: `/reserve`,
verb: 'post'
}
});
Self.reserve = async params => {
let thisTicketIsEditable = await Self.app.models.Ticket.isEditable(params.ticketFk);
if (!thisTicketIsEditable)
throw new UserError(`The sales of this ticket can't be modified`);
2018-12-27 11:54:16 +00:00
for (let i = 0; i < params.sales.length; i++)
await Self.app.models.Sale.update({id: params.sales[i].id}, {reserved: params.reserved});
};
};