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

47 lines
1.2 KiB
JavaScript

const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
module.exports = Self => {
Self.remoteMethod('getLanded', {
description: 'Returns ticket available landed date',
accessType: 'READ',
accepts: [{
arg: 'data',
type: 'Object',
required: true,
description: 'shipped, addressFk, agencyModeFk, warehouseFk',
http: {source: 'body'}
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/getLanded`,
verb: 'POST'
}
});
Self.getLanded = async data => {
let stmts = [];
let agencyMode = await Self.app.models.AgencyMode.findById(data.agencyModeFk);
stmts.push(new ParameterizedSQL(
`CALL vn.agencyHourGetLanded(?, ?, ?, ?)`, [
data.shipped,
data.addressFk,
agencyMode.agencyFk,
data.warehouseFk
]
));
let rsIndex = stmts.push(
`SELECT * FROM tmp.agencyHourGetLanded`) - 1;
let sql = ParameterizedSQL.join(stmts, ';');
let landed = await Self.rawStmt(sql);
return landed[rsIndex][0];
};
};