34 lines
1008 B
JavaScript
34 lines
1008 B
JavaScript
|
|
let UserError = require('vn-loopback/util/user-error');
|
|
|
|
module.exports = Self => {
|
|
Self.remoteMethodCtx('reserve', {
|
|
description: 'Change the state of a ticket',
|
|
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(ctx, params) => {
|
|
let thisTicketIsEditable = await Self.app.models.Ticket.isEditable(ctx, params.ticketFk);
|
|
if (!thisTicketIsEditable)
|
|
throw new UserError(`The sales of this ticket can't be modified`);
|
|
|
|
for (let i = 0; i < params.sales.length; i++)
|
|
await Self.app.models.Sale.update({id: params.sales[i].id}, {reserved: params.reserved});
|
|
};
|
|
};
|