Fixed and adjusted to cds5
This commit is contained in:
@@ -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"
|
||||
},
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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 ()=>{
|
||||
|
||||
Reference in New Issue
Block a user