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