Cosmetics

This commit is contained in:
Christian Georgi
2020-02-09 11:26:45 +00:00
parent 452b442246
commit 2ca71b0f7d
2 changed files with 3 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
using { sap.capire.bookshop as my } from '../db/schema';
@path:'/browse'
// @impl: './cat-service.js'
service CatalogService {
@readonly entity Books as SELECT from my.Books {*,

View File

@@ -5,18 +5,17 @@ const { Books } = cds.entities
module.exports = cds.service.impl(srv => {
srv.after ('READ', 'Books', each => each.stock > 111 && _addDiscount2(each,11))
srv.before ('CREATE', 'Orders', _reduceStock)
// srv.before ('*', (req) => { console.debug ('>>>', req.method, req.target && req.target.name) })
// srv.before ('*', (req) => { console.debug ('>>>', req.method, req.target.name) })
})
/** Add some discount for overstocked books */
function _addDiscount2 (each,discount) {
each.title += ` -- ${discount}% discount!`
}
/** Reduce stock of ordered books if available stock suffices */
async function _reduceStock (req) {
const { Items: OrderItems } = req.data
// req.on('failed', () => {console.debug ('>>> failed for order', req.data.ID)})
// req.on('failed', () => { console.debug ('>>> failed for order', req.data.ID) })
return cds.transaction(req) .run (()=> OrderItems.map (order =>
UPDATE (Books) .set ('stock -=', order.amount)