2018-07-03 13:00:16 +00:00
|
|
|
|
2018-08-02 07:49:00 +00:00
|
|
|
let UserError = require('../../helpers').UserError;
|
|
|
|
|
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,
|
|
|
|
description: '[sales IDs], actualTicketFk, 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.actualTicketFk);
|
|
|
|
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
|
|
|
|
|
|
|
for (let i = 0; i < params.sales.length; i++) {
|
|
|
|
await Self.app.models.Sale.update({id: params.sales[i].id}, {reserved: params.reserved});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|