.
This commit is contained in:
@@ -21,6 +21,8 @@
|
|||||||
},
|
},
|
||||||
"cds": {
|
"cds": {
|
||||||
"requires": {
|
"requires": {
|
||||||
|
"extensibility": true,
|
||||||
|
"-toggles": true,
|
||||||
"db": {
|
"db": {
|
||||||
"kind": "sql"
|
"kind": "sql"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
const cds = require('@sap/cds')
|
const cds = require('@sap/cds')
|
||||||
|
class CatalogService extends cds.ApplicationService { async init(){
|
||||||
class CatalogService extends cds.ApplicationService { init(){
|
|
||||||
|
|
||||||
const { Books } = cds.entities ('sap.capire.bookshop')
|
const { Books } = cds.entities ('sap.capire.bookshop')
|
||||||
|
const { ListOfBooks } = this.entities
|
||||||
|
|
||||||
|
this.on('READ','ListOfBooks', ()=>{
|
||||||
|
Error.stackTraceLimit = 22
|
||||||
|
cds._debug = true
|
||||||
|
return SELECT.from (ListOfBooks)
|
||||||
|
})
|
||||||
|
|
||||||
// Reduce stock of ordered books if available stock suffices
|
// Reduce stock of ordered books if available stock suffices
|
||||||
this.on ('submitOrder', async req => {
|
this.on ('submitOrder', async req => {
|
||||||
const {book,quantity} = req.data
|
const {book,quantity} = req.data
|
||||||
if (quantity < 1) return req.reject (400,`quantity has to be 1 or more`)
|
if (quantity < 1) return req.reject (400,`quantity has to be 1 or more`)
|
||||||
|
cds._debug = true
|
||||||
let b = await SELECT `stock` .from (Books,book)
|
let b = await SELECT `stock` .from (Books,book)
|
||||||
if (!b) return req.error (404,`Book #${book} doesn't exist`)
|
if (!b) return req.error (404,`Book #${book} doesn't exist`)
|
||||||
let {stock} = b
|
let {stock} = b
|
||||||
@@ -22,7 +29,8 @@ class CatalogService extends cds.ApplicationService { init(){
|
|||||||
if (each.stock > 111) each.title += ` -- 11% discount!`
|
if (each.stock > 111) each.title += ` -- 11% discount!`
|
||||||
})
|
})
|
||||||
|
|
||||||
return super.init()
|
await super.init()
|
||||||
|
return
|
||||||
}}
|
}}
|
||||||
|
|
||||||
module.exports = { CatalogService }
|
module.exports = { CatalogService }
|
||||||
|
|||||||
Reference in New Issue
Block a user