49 lines
1.2 KiB
JavaScript
49 lines
1.2 KiB
JavaScript
module.exports = Self => {
|
|
Self.remoteMethod('getUpcomingDeliveries', {
|
|
description: 'Returns the upcomings deliveries',
|
|
accessType: 'READ',
|
|
accepts: [],
|
|
returns: {
|
|
type: ['object'],
|
|
root: true
|
|
},
|
|
http: {
|
|
path: `/getUpcomingDeliveries`,
|
|
verb: 'GET'
|
|
}
|
|
});
|
|
|
|
Self.getUpcomingDeliveries = async options => {
|
|
let myOptions = {};
|
|
|
|
if (typeof options == 'object')
|
|
Object.assign(myOptions, options);
|
|
|
|
const [zones] = await Self.rawSql('CALL vn.zone_upcomingDeliveries()', null, myOptions);
|
|
|
|
if (!zones.length) return;
|
|
|
|
const details = [];
|
|
|
|
for (let zone of zones) {
|
|
const shipped = zone.shipped;
|
|
|
|
let zoneDetail = details.find(zone => {
|
|
return zone.shipped.toString() == shipped.toString();
|
|
});
|
|
|
|
if (!zoneDetail) {
|
|
zoneDetail = {
|
|
shipped: shipped,
|
|
lines: []
|
|
};
|
|
details.push(zoneDetail);
|
|
}
|
|
|
|
zoneDetail.lines.push(zone);
|
|
}
|
|
|
|
return details;
|
|
};
|
|
};
|