2018-07-24 10:14:35 +00:00
|
|
|
|
|
|
|
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
|
|
|
|
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethod('getShipped', {
|
|
|
|
description: 'Returns ticket available shipment date',
|
|
|
|
accessType: 'READ',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'data',
|
|
|
|
type: 'Object',
|
|
|
|
required: true,
|
|
|
|
description: 'landed, addressFk, agencyModeFk',
|
|
|
|
http: {source: 'body'}
|
|
|
|
}],
|
|
|
|
returns: {
|
|
|
|
type: 'object',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/getShipped`,
|
|
|
|
verb: 'POST'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Self.getShipped = async data => {
|
2018-08-16 11:12:18 +00:00
|
|
|
let stmts = [];
|
2018-07-24 10:14:35 +00:00
|
|
|
let agencyMode = await Self.app.models.AgencyMode.findById(data.agencyModeFk);
|
|
|
|
|
2018-08-16 11:12:18 +00:00
|
|
|
stmts.push(new ParameterizedSQL(
|
|
|
|
`CALL vn.agencyHourGetShipped(?, ?, ?)`, [
|
|
|
|
data.landed,
|
|
|
|
data.addressFk,
|
|
|
|
agencyMode.agencyFk
|
|
|
|
]
|
|
|
|
));
|
2018-07-24 10:14:35 +00:00
|
|
|
|
2018-08-16 11:12:18 +00:00
|
|
|
let rsIndex = stmts.push(`
|
|
|
|
SELECT * FROM tmp.agencyHourGetShipped`) - 1;
|
2018-07-24 10:14:35 +00:00
|
|
|
|
2018-08-16 11:12:18 +00:00
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
let shipped = await Self.rawStmt(sql);
|
|
|
|
|
|
|
|
return shipped[rsIndex][0];
|
2018-07-24 10:14:35 +00:00
|
|
|
};
|
|
|
|
};
|