salix/modules/order/back/methods/order/newFromTicket.js

35 lines
900 B
JavaScript

module.exports = Self => {
Self.remoteMethod('newFromTicket', {
description: 'Create a new order and returns the new ID',
accessType: 'WRITE',
accepts: [{
arg: 'ticketFk',
type: 'number',
description: 'The ticket id',
required: true
}],
returns: {
type: 'number',
root: true
},
http: {
path: `/newFromTicket`,
verb: 'post'
}
});
Self.newFromTicket = async ticketFk => {
let ticket = await Self.app.models.Ticket.findOne({
where: {id: ticketFk}
});
let landed = ticket.landed;
let addressFk = ticket.addressFk;
let agencyModeFk = ticket.agencyModeFk;
let orderID = await Self.app.models.Order.new(landed, addressFk, agencyModeFk);
return orderID;
};
};