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