Slightly adjust JS files for samples to accomodate types
This commit is contained in:
@@ -2,7 +2,8 @@ const cds = require('@sap/cds')
|
|||||||
|
|
||||||
class CatalogService extends cds.ApplicationService { init(){
|
class CatalogService extends cds.ApplicationService { init(){
|
||||||
|
|
||||||
const { Books } = this.entities ('sap.capire.bookshop')
|
//const { Books } = this.entities ('sap.capire.bookshop')
|
||||||
|
const { Books, Book } = require('../@types/sap/capire/bookshop')
|
||||||
|
|
||||||
// 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 => {
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ module.exports = async()=>{ // called by server.js
|
|||||||
const db = await cds.connect.to ('db')
|
const db = await cds.connect.to ('db')
|
||||||
|
|
||||||
// reflect entity definitions used below...
|
// reflect entity definitions used below...
|
||||||
const { Books } = db.entities ('sap.capire.bookshop')
|
//const { Books } = db.entities ('sap.capire.bookshop')
|
||||||
|
const { Books, Book } = require('../@types/sap/capire/bookshop')
|
||||||
|
|
||||||
//
|
//
|
||||||
// Delegate requests to read reviews to the ReviewsService
|
// Delegate requests to read reviews to the ReviewsService
|
||||||
@@ -19,8 +20,8 @@ module.exports = async()=>{ // called by server.js
|
|||||||
//
|
//
|
||||||
CatalogService.prepend (srv => srv.on ('READ', 'Books/reviews', (req) => {
|
CatalogService.prepend (srv => srv.on ('READ', 'Books/reviews', (req) => {
|
||||||
console.debug ('> delegating request to ReviewsService')
|
console.debug ('> delegating request to ReviewsService')
|
||||||
const [id] = req.params, { columns, limit } = req.query.SELECT
|
const [id] = req.params, { columns, limit } = 'SELECT' in req.query ? req.query.SELECT : {columns: [], limit: { rows: 0 }}
|
||||||
return ReviewsService.read ('Reviews',columns).limit(limit).where({subject:String(id)})
|
return ReviewsService.read ('Reviews',columns).limit(limit.rows).where({subject:String(id)})
|
||||||
}))
|
}))
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -28,7 +29,7 @@ module.exports = async()=>{ // called by server.js
|
|||||||
//
|
//
|
||||||
CatalogService.on ('OrderedBook', async (msg) => {
|
CatalogService.on ('OrderedBook', async (msg) => {
|
||||||
const { book, quantity, buyer } = msg.data
|
const { book, quantity, buyer } = msg.data
|
||||||
const { title, price } = await db.tx(msg).read (Books, book, b => { b.title, b.price })
|
const { title, price } = await db.tx(msg).read ('Books').where('ID = ' + book.ID).columns((/** @type {Book} */ b) => { b.title, b.price })
|
||||||
return OrdersService.tx(msg).create ('Orders').entries({
|
return OrdersService.tx(msg).create ('Orders').entries({
|
||||||
OrderNo: 'Order at '+ (new Date).toLocaleString(),
|
OrderNo: 'Order at '+ (new Date).toLocaleString(),
|
||||||
Items: [{ product:{ID:`${book}`}, title, price, quantity }],
|
Items: [{ product:{ID:`${book}`}, title, price, quantity }],
|
||||||
|
|||||||
Reference in New Issue
Block a user