35 lines
875 B
JavaScript
35 lines
875 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 orderID = await Self.app.models.Order.new({
|
|
addressFk: ticket.addressFk,
|
|
landed: ticket.landed,
|
|
agencyModeFk: ticket.agencyModeFk
|
|
});
|
|
|
|
return orderID;
|
|
};
|
|
};
|