diff --git a/bookshop/package.json b/bookshop/package.json index 25a9f529..e7125251 100644 --- a/bookshop/package.json +++ b/bookshop/package.json @@ -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" }, diff --git a/bookshop/srv/cat-service.js b/bookshop/srv/cat-service.js index 4676dcd5..a27aa397 100644 --- a/bookshop/srv/cat-service.js +++ b/bookshop/srv/cat-service.js @@ -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 } } @@ -16,10 +16,8 @@ class CatalogService extends cds.ApplicationService { init(){ }) // Add some discount for overstocked books - this.after ('READ','Books', each => { - if (each.stock > 111) { - each.title += ` -- 11% discount!` - } + this.after ('READ','ListOfBooks', each => { + if (each.stock > 111) each.title += ` -- 11% discount!` }) return super.init() diff --git a/test/messaging.test.js b/test/messaging.test.js index 42d20d38..3e2176b1 100644 --- a/test/messaging.test.js +++ b/test/messaging.test.js @@ -20,11 +20,11 @@ describe('Messaging', ()=>{ let N=0, received=[], M=0 it ('should add messaging event handlers', ()=>{ - srv.on('reviewed', (msg,next)=> { received.push(msg); return next() }) + srv.on('reviewed', (msg)=> received.push(msg)) }) it ('should add more messaging event handlers', ()=>{ - srv.on('reviewed', (_,next)=> { ++M; return next() }) + srv.on('reviewed', ()=> ++M) }) it ('should add review', async ()=>{