salix/services/loopback/common/methods/ticket/create.js

41 lines
1.2 KiB
JavaScript

module.exports = Self => {
Self.remoteMethod('create', {
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: `/create`,
verb: 'post'
}
});
Self.create = 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.wharehouseFk,
params.companyFk,
params.addressFk,
params.agencyModeFk,
params.routeFk,
params.landed
]);
return result;
};
};