Cosmetics
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using { sap.capire.bookshop as my } from '../db/schema';
|
using { sap.capire.bookshop as my } from '../db/schema';
|
||||||
|
|
||||||
@path:'/browse'
|
@path:'/browse'
|
||||||
|
// @impl: './cat-service.js'
|
||||||
service CatalogService {
|
service CatalogService {
|
||||||
|
|
||||||
@readonly entity Books as SELECT from my.Books {*,
|
@readonly entity Books as SELECT from my.Books {*,
|
||||||
|
|||||||
@@ -5,14 +5,13 @@ const { Books } = cds.entities
|
|||||||
module.exports = cds.service.impl(srv => {
|
module.exports = cds.service.impl(srv => {
|
||||||
srv.after ('READ', 'Books', each => each.stock > 111 && _addDiscount2(each,11))
|
srv.after ('READ', 'Books', each => each.stock > 111 && _addDiscount2(each,11))
|
||||||
srv.before ('CREATE', 'Orders', _reduceStock)
|
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 */
|
/** 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
|
||||||
|
|||||||
Reference in New Issue
Block a user