Merge branch 'master' into temporal

This commit is contained in:
Daniel
2021-04-10 13:08:31 +02:00
5 changed files with 37 additions and 27 deletions

View File

@@ -4,7 +4,7 @@
"description": "A simple self-contained bookshop service.",
"dependencies": {
"@capire/common": "*",
"@sap/cds": ">=4",
"@sap/cds": "^5.0.4",
"express": "^4.17.1",
"passport": "0.4.1"
},

View File

@@ -5,10 +5,10 @@ class CatalogService extends cds.ApplicationService { init(){
// Reduce stock of ordered books if available stock suffices
this.on ('submitOrder', async req => {
const {book,amount} = req.data, tx = cds.tx(req)
let {stock} = await tx.read('stock').from(Books,book)
const {book,amount} = req.data
let {stock} = await SELECT `stock` .from (Books,book)
if (stock >= amount) {
await tx.update (Books,book).with ({ stock: stock -= amount })
await UPDATE (Books,book) .with (`stock -=`, amount)
await this.emit ('OrderedBook', { book, amount, buyer:req.user.id })
return { stock }
}
@@ -17,9 +17,7 @@ class CatalogService extends cds.ApplicationService { init(){
// Add some discount for overstocked books
this.after ('READ','ListOfBooks', each => {
if (each.stock > 111) {
each.title += ` -- 11% discount!`
}
if (each.stock > 111) each.title += ` -- 11% discount!`
})
return super.init()