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 => { let stmts = []; let agencyMode = await Self.app.models.AgencyMode.findById(data.agencyModeFk); stmts.push(new ParameterizedSQL( `CALL vn.agencyHourGetShipped(?, ?, ?)`, [ data.landed, data.addressFk, agencyMode.agencyFk ] )); let rsIndex = stmts.push(` SELECT * FROM tmp.agencyHourGetShipped`) - 1; let sql = ParameterizedSQL.join(stmts, ';'); let shipped = await Self.rawStmt(sql); return shipped[rsIndex][0]; }; };