Cosmetics

This commit is contained in:
Christian Georgi
2020-02-10 22:19:14 +00:00
parent 4ad21a47d6
commit 659fe52509

View File

@@ -4,8 +4,10 @@ const cds = require('@sap/cds')
module.exports = cds.service.impl(srv => {
const { OrderItems } = srv.entities ('sap.capire.bookshop')
srv.after (['READ','EDIT'], 'Orders', _calculateTotals)
// on-the-fly calculate the total Order price based on the OrderItems' netAmounts
srv.after (['READ','EDIT'], 'Orders', async (orders, req) => {
async function _calculateTotals (orders, req) {
const ordersByID = Array.isArray(orders)
? orders.reduce ((all,o) => { (all[o.ID] = o).total=0; return all },{})
: { [orders.ID]: orders }
@@ -15,5 +17,6 @@ module.exports = cds.service.impl(srv => {
) .then (items =>
items.forEach (item => ordersByID [item.parent_ID] .total += item.netAmount)
)
})
}
})