From 4ae16e8fd261082f448e658595e2bafe992b782b Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 15 Mar 2020 12:12:18 +0100 Subject: [PATCH] Cleaned up delegation --- reviews/test/bookshop/server.js | 20 +++++++++----------- reviews/test/requests.http | 6 ++++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/reviews/test/bookshop/server.js b/reviews/test/bookshop/server.js index 7d17dbb8..22075d5f 100644 --- a/reviews/test/bookshop/server.js +++ b/reviews/test/bookshop/server.js @@ -10,21 +10,19 @@ cds.on('listening', async()=>{ console.debug ('> received:', msg.event, msg.data) const { Books } = db.entities('sap.capire.bookshop') const { subject, rating } = msg.data - const tx = db // TODO: db.transaction (msg) - // return tx.run (UPDATE (Books, subject) .with ({rating})) - return tx.update (Books, subject) .with ({rating}) + const tx = db.tx (msg) // TODO: db.tx(msg) fully implemented? + return tx.update (Books,subject) .with ({rating}) }) // delegate requests to read reviews to ReviewsService const CatalogService = await cds.connect.to ('CatalogService') - CatalogService.impl (() => { - CatalogService.on ('READ', 'Books/reviews', (req) => { - const { Reviews } = ReviewsService.entities - const [ subject ] = req.params - const tx = ReviewsService.transaction (req) - return tx.run (SELECT.from (Reviews) .where ({subject})) - }) - }) + CatalogService.impl (srv => srv.on ('READ', 'Books/reviews', (req) => { + console.debug ('> delegating to ReviewsService') + const { Reviews } = ReviewsService.entities + const [ subject ] = req.params + const tx = ReviewsService.tx (req) + return tx.read (Reviews,{subject}) .columns (req.query.SELECT.columns) + })) }) diff --git a/reviews/test/requests.http b/reviews/test/requests.http index d1c89504..c311be81 100644 --- a/reviews/test/requests.http +++ b/reviews/test/requests.http @@ -5,10 +5,12 @@ ### 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 -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)?