new messaging

This commit is contained in:
D065023
2020-09-15 15:30:14 +02:00
parent 6fdd91b8c8
commit a71aaf75a1
8 changed files with 17 additions and 22 deletions

View File

@@ -4,7 +4,7 @@
"dependencies": {
"@capire/bookshop": "../bookshop",
"@capire/reviews": "../reviews",
"@sap/cds": "^3.33.1",
"@sap/cds": "^4",
"express": "^4.17.1"
},
"cds": {

View File

@@ -11,6 +11,7 @@ cds.once('served', async ({CatalogService}) => {
// reflect entity definitions used below...
const { Books } = cds.entities('sap.capire.bookshop')
const { Reviews } = cds.entities('ReviewsService')
const messaging = await cds.connect.to('messaging')
// prepend the following handler so it overrides the default handler
CatalogService.prepend (srv => srv.on ('READ', 'Books/reviews', (req) => {
@@ -19,9 +20,7 @@ cds.once('served', async ({CatalogService}) => {
return SELECT(columns).from(Reviews).limit(limit).where({subject:String(id)})
}))
// subscribe to events emitted by ReviewsService
const ReviewsService = await cds.connect.to ('ReviewsService')
ReviewsService.on ('reviewed', (msg) => {
messaging.on ('review/reviewed', (msg) => {
console.debug ('> received:', msg.event, msg.data)
const { subject, rating } = msg.data
return UPDATE(Books,subject).with({rating})