Cleaned up delegation
This commit is contained in:
@@ -10,21 +10,19 @@ cds.on('listening', async()=>{
|
|||||||
console.debug ('> received:', msg.event, msg.data)
|
console.debug ('> received:', msg.event, msg.data)
|
||||||
const { Books } = db.entities('sap.capire.bookshop')
|
const { Books } = db.entities('sap.capire.bookshop')
|
||||||
const { subject, rating } = msg.data
|
const { subject, rating } = msg.data
|
||||||
const tx = db // TODO: db.transaction (msg)
|
const tx = db.tx (msg) // TODO: db.tx(msg) fully implemented?
|
||||||
// return tx.run (UPDATE (Books, subject) .with ({rating}))
|
|
||||||
return tx.update (Books,subject) .with ({rating})
|
return tx.update (Books,subject) .with ({rating})
|
||||||
})
|
})
|
||||||
|
|
||||||
// delegate requests to read reviews to ReviewsService
|
// delegate requests to read reviews to ReviewsService
|
||||||
const CatalogService = await cds.connect.to ('CatalogService')
|
const CatalogService = await cds.connect.to ('CatalogService')
|
||||||
CatalogService.impl (() => {
|
CatalogService.impl (srv => srv.on ('READ', 'Books/reviews', (req) => {
|
||||||
CatalogService.on ('READ', 'Books/reviews', (req) => {
|
console.debug ('> delegating to ReviewsService')
|
||||||
const { Reviews } = ReviewsService.entities
|
const { Reviews } = ReviewsService.entities
|
||||||
const [ subject ] = req.params
|
const [ subject ] = req.params
|
||||||
const tx = ReviewsService.transaction (req)
|
const tx = ReviewsService.tx (req)
|
||||||
return tx.run (SELECT.from (Reviews) .where ({subject}))
|
return tx.read (Reviews,{subject}) .columns (req.query.SELECT.columns)
|
||||||
})
|
}))
|
||||||
})
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,12 @@
|
|||||||
|
|
||||||
|
|
||||||
### Request to CatalogService > delegated to ReviewsService
|
### Request to CatalogService > delegated to ReviewsService
|
||||||
GET http://localhost:4004/browse/Books(201)/reviews
|
GET http://localhost:4004/browse/Books(201)/reviews?
|
||||||
|
&$select=rating,date,reviewer,title
|
||||||
|
|
||||||
### Alternative OData URL
|
### Alternative OData URL
|
||||||
GET http://localhost:4004/browse/Books/201/reviews
|
GET http://localhost:4004/browse/Books/201/reviews?
|
||||||
|
&$select=rating,date,reviewer,title
|
||||||
|
|
||||||
###
|
###
|
||||||
GET http://localhost:4004/browse/Books(201)?
|
GET http://localhost:4004/browse/Books(201)?
|
||||||
|
|||||||
Reference in New Issue
Block a user