Cosmetics
This commit is contained in:
@@ -4,8 +4,10 @@ const cds = require('@sap/cds')
|
|||||||
module.exports = cds.service.impl(srv => {
|
module.exports = cds.service.impl(srv => {
|
||||||
const { OrderItems } = srv.entities ('sap.capire.bookshop')
|
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
|
// 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)
|
const ordersByID = Array.isArray(orders)
|
||||||
? orders.reduce ((all,o) => { (all[o.ID] = o).total=0; return all },{})
|
? orders.reduce ((all,o) => { (all[o.ID] = o).total=0; return all },{})
|
||||||
: { [orders.ID]: orders }
|
: { [orders.ID]: orders }
|
||||||
@@ -15,5 +17,6 @@ module.exports = cds.service.impl(srv => {
|
|||||||
) .then (items =>
|
) .then (items =>
|
||||||
items.forEach (item => ordersByID [item.parent_ID] .total += item.netAmount)
|
items.forEach (item => ordersByID [item.parent_ID] .total += item.netAmount)
|
||||||
)
|
)
|
||||||
})
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user