salix/modules/zone/back/methods/zone/getUpcomingDeliveries.js

49 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-05-15 10:17:34 +00:00
module.exports = Self => {
2023-06-01 06:32:06 +00:00
Self.remoteMethodCtx('getUpcomingDeliveries', {
2020-05-15 10:17:34 +00:00
description: 'Returns the upcomings deliveries',
accessType: 'READ',
accepts: [],
returns: {
type: ['object'],
2020-05-15 10:17:34 +00:00
root: true
},
http: {
path: `/getUpcomingDeliveries`,
verb: 'GET'
}
});
2023-06-01 06:32:06 +00:00
Self.getUpcomingDeliveries = async(ctx, options) => {
const myOptions = {userId: ctx.req.accessToken.userId};
if (typeof options == 'object')
Object.assign(myOptions, options);
const [zones] = await Self.rawSql('CALL vn.zone_upcomingDeliveries()', null, myOptions);
2020-05-15 10:17:34 +00:00
if (!zones.length) return;
2020-05-15 10:17:34 +00:00
const details = [];
for (let zone of zones) {
const shipped = zone.shipped;
let zoneDetail = details.find(zone => {
2020-05-19 06:46:42 +00:00
return zone.shipped.toString() == shipped.toString();
2020-05-15 10:17:34 +00:00
});
if (!zoneDetail) {
zoneDetail = {
shipped: shipped,
lines: []
};
details.push(zoneDetail);
}
zoneDetail.lines.push(zone);
}
return details;
};
};