salix/services/loopback/common/methods/sale/reserve.js

35 lines
1009 B
JavaScript
Raw Normal View History

let UserError = require('../../helpers').UserError;
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)
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});
}
};
};