2020-09-19 11:02:00 +00:00
|
|
|
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
|
|
|
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
|
|
|
|
|
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethod('byWarehouse', {
|
|
|
|
description: 'Returns a list of agencies from a warehouse',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'filter',
|
2021-06-18 13:05:03 +00:00
|
|
|
type: 'object',
|
2020-09-19 11:02:00 +00:00
|
|
|
description: `Filter defining where, order, offset, and limit - must be a JSON-encoded string`
|
|
|
|
}],
|
|
|
|
returns: {
|
|
|
|
type: ['object'],
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/byWarehouse`,
|
|
|
|
verb: 'GET'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-06-18 13:05:03 +00:00
|
|
|
Self.byWarehouse = async(filter, options) => {
|
2020-09-19 11:02:00 +00:00
|
|
|
const conn = Self.dataSource.connector;
|
|
|
|
const where = {isActive: true};
|
2021-11-18 10:17:30 +00:00
|
|
|
const myOptions = {};
|
2021-06-18 13:05:03 +00:00
|
|
|
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
|
|
|
|
2020-09-19 11:02:00 +00:00
|
|
|
filter = mergeFilters(filter, {where});
|
|
|
|
|
|
|
|
let stmt = new ParameterizedSQL(
|
2020-09-23 12:13:44 +00:00
|
|
|
`SELECT id, name, warehouseFk
|
2020-09-19 11:02:00 +00:00
|
|
|
FROM (
|
|
|
|
SELECT DISTINCT am.id, am.name, am.isActive, zw.warehouseFk
|
|
|
|
FROM zoneWarehouse zw
|
|
|
|
JOIN zone z ON z.id = zw.zoneFk
|
2021-06-18 13:05:03 +00:00
|
|
|
JOIN agencyMode am ON am.id = z.agencyModeFk) am`,
|
|
|
|
null, myOptions);
|
|
|
|
|
2020-09-19 11:02:00 +00:00
|
|
|
stmt.merge(conn.makeSuffix(filter));
|
|
|
|
|
|
|
|
return conn.executeStmt(stmt);
|
|
|
|
};
|
|
|
|
};
|