This commit is contained in:
D065023
2020-01-08 13:45:53 +01:00
parent 9ba5aae999
commit dc1ea91d9e
4 changed files with 12 additions and 48 deletions

View File

@@ -3,11 +3,7 @@ const { Books } = cds.entities
/** Service implementation for CatalogService */
module.exports = cds.service.impl(function () {
this.after(
'READ',
'Books',
each => each.stock > 111 && _addDiscount2(each, 11)
)
this.after('READ', 'Books', each => each.stock > 111 && _addDiscount2(each, 11))
this.before('CREATE', 'Orders', _reduceStock)
})
@@ -28,12 +24,6 @@ async function _reduceStock (req) {
)
)
all.forEach((affectedRows, i) => {
if (affectedRows === 0)
req.error(
409,
`${OrderItems[i].amount} exceeds stock for book #${
OrderItems[i].book_ID
}`
)
if (affectedRows === 0) req.error(409, `${OrderItems[i].amount} exceeds stock for book #${OrderItems[i].book_ID}`)
})
}