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

58 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-05-30 06:41:08 +00:00
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
2019-01-25 10:58:50 +00:00
module.exports = Self => {
Self.remoteMethod('getLanded', {
2019-01-25 10:58:50 +00:00
description: 'Returns the first shipped and landed possible for params',
accessType: 'READ',
accepts: [{
2019-05-30 06:41:08 +00:00
arg: 'shipped',
type: 'date',
required: true
},
{
arg: 'addressFk',
type: 'number',
required: true
},
{
arg: 'agencyModeFk',
type: 'number',
required: true
},
{
arg: 'warehouseFk',
type: 'number',
required: true
2019-01-25 10:58:50 +00:00
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/getLanded`,
verb: 'get'
}
});
Self.getLanded = async(shipped, addressFk, agencyModeFk, warehouseFk) => {
2019-05-30 06:41:08 +00:00
let stmts = [];
stmts.push(new ParameterizedSQL(
`CALL vn.zone_getLanded(?, ?, ?, ?)`, [
shipped,
addressFk,
agencyModeFk,
warehouseFk
2019-05-30 06:41:08 +00:00
]
));
let rsIndex = stmts.push(
`SELECT * FROM tmp.zoneGetLanded`) - 1;
stmts.push(`DROP TEMPORARY TABLE tmp.zoneGetLanded`);
2019-05-30 06:41:08 +00:00
let sql = ParameterizedSQL.join(stmts, ';');
let landed = await Self.rawStmt(sql);
2019-01-25 10:58:50 +00:00
2019-05-30 06:41:08 +00:00
return landed[rsIndex][0];
2019-01-25 10:58:50 +00:00
};
};