salix/modules/zone/back/methods/agency-mode/byWarehouse.js

46 lines
1.4 KiB
JavaScript
Raw Normal View History

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',
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'
}
});
Self.byWarehouse = async(filter, options) => {
2020-09-19 11:02:00 +00:00
const conn = Self.dataSource.connector;
const where = {isActive: true};
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
2020-09-19 11:02:00 +00:00
filter = mergeFilters(filter, {where});
let stmt = new ParameterizedSQL(
`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
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);
};
};