42 lines
977 B
JavaScript
42 lines
977 B
JavaScript
module.exports = Self => {
|
|
Self.remoteMethod('getWasteDetail', {
|
|
description: 'Returns the ',
|
|
accessType: 'READ',
|
|
accepts: [],
|
|
returns: {
|
|
type: ['Object'],
|
|
root: true
|
|
},
|
|
http: {
|
|
path: `/getWasteDetail`,
|
|
verb: 'GET'
|
|
}
|
|
});
|
|
|
|
Self.getWasteDetail = async() => {
|
|
const [wastes] = await Self.rawSql(`CALL bs.weekWaste_getDetail()`);
|
|
|
|
const details = [];
|
|
|
|
for (let waste of wastes) {
|
|
const buyerName = waste.buyer;
|
|
|
|
let buyerDetail = details.find(waste => {
|
|
return waste.buyer == buyerName;
|
|
});
|
|
|
|
if (!buyerDetail) {
|
|
buyerDetail = {
|
|
buyer: buyerName,
|
|
lines: []
|
|
};
|
|
details.push(buyerDetail);
|
|
}
|
|
|
|
buyerDetail.lines.push(waste);
|
|
}
|
|
|
|
return details;
|
|
};
|
|
};
|