This commit is contained in:
D065023
2020-01-28 16:04:32 +01:00
parent e694fbaf13
commit 6d3e9a211a

View File

@@ -13,15 +13,14 @@ module.exports = cds.service.impl(async function () {
const orders = await cds.tx(msg).run(SELECT.from(Orders).where({ createdBy: BUSINESSPARTNER })) const orders = await cds.tx(msg).run(SELECT.from(Orders).where({ createdBy: BUSINESSPARTNER }))
console.log(orders) console.log(orders)
}) })
})
/** Add some discount for overstocked books */ /** Add some discount for overstocked books */
function _addDiscount2(each, discount) { function _addDiscount2(each, discount) {
each.title += ` -- ${discount}% discount!` each.title += ` -- ${discount}% discount!`
} }
/** Reduce stock of ordered books if available stock suffices */ /** Reduce stock of ordered books if available stock suffices */
async function _reduceStock(req) { async function _reduceStock(req) {
const { Items: OrderItems } = req.data const { Items: OrderItems } = req.data
return cds.transaction(req).run(() => OrderItems.map(order => return cds.transaction(req).run(() => OrderItems.map(order =>
UPDATE(Books).set('stock -=', order.amount) UPDATE(Books).set('stock -=', order.amount)
@@ -31,4 +30,5 @@ async function _reduceStock(req) {
`${OrderItems[i].amount} exceeds stock for book #${OrderItems[i].book_ID}` `${OrderItems[i].amount} exceeds stock for book #${OrderItems[i].book_ID}`
) )
})) }))
} }
})