salix/modules/zone/back/methods/agency/getShipped.js

59 lines
1.5 KiB
JavaScript

const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
module.exports = Self => {
Self.remoteMethod('getShipped', {
description: 'Returns the first shipped possible for params',
accessType: 'READ',
accepts: [{
arg: 'landed',
type: 'date',
required: true
},
{
arg: 'addressFk',
type: 'number',
required: true
},
{
arg: 'agencyModeFk',
type: 'number',
required: true
},
{
arg: 'warehouseFk',
type: 'number',
required: true
}],
returns: {
type: 'date',
root: true
},
http: {
path: `/getShipped`,
verb: 'get'
}
});
Self.getShipped = async(landed, addressFk, agencyModeFk, warehouseFk)=> {
let stmts = [];
stmts.push(new ParameterizedSQL(
`CALL vn.zone_getShippedWarehouse(?, ?, ?)`, [
landed,
addressFk,
agencyModeFk
]
));
let rsIndex = stmts.push(new ParameterizedSQL(
`SELECT * FROM tmp.zoneGetShipped WHERE warehouseFk = ?`, [
warehouseFk
]
)) - 1;
let sql = ParameterizedSQL.join(stmts, ';');
let shipped = await Self.rawStmt(sql);
return shipped[rsIndex][0];
};
};