41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
module.exports = Self => {
|
|
Self.remoteMethod('new', {
|
|
description: 'Create a newticket and returns the new ID',
|
|
accessType: 'WRITE',
|
|
accepts: [{
|
|
arg: 'params',
|
|
type: 'object',
|
|
required: true,
|
|
description: 'ClientFk, Shipped, WharehouseFk, CompanyFk, AddressFk, AgencyModeFk, RouteFk, Landed',
|
|
http: {source: 'body'}
|
|
}],
|
|
returns: {
|
|
type: 'number',
|
|
root: true
|
|
},
|
|
http: {
|
|
path: `/new`,
|
|
verb: 'post'
|
|
}
|
|
});
|
|
|
|
Self.new = async params => {
|
|
let existsAddress = await Self.app.models.Address.findOne({where: {id: params.addressFk, clientFk: params.clientFk}});
|
|
if (!existsAddress)
|
|
throw new Error(`This address doesn't exist`);
|
|
|
|
let query = `CALL vn.ticketListCreate(?, ?, ?, ?, ?, ?, ?, ?);`;
|
|
let result = await Self.rawSql(query, [
|
|
params.clientFk,
|
|
params.shipped,
|
|
params.warehouseFk,
|
|
params.companyFk | 442,
|
|
params.addressFk,
|
|
params.agencyModeFk,
|
|
params.routeFk | null,
|
|
params.landed
|
|
]);
|
|
return result[0][0].vNewTicket;
|
|
};
|
|
};
|