messaging
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
ID;modifiedAt;createdAt;createdBy;modifiedBy;OrderNo;currency_code
|
||||
7e2f2640-6866-4dcf-8f4d-3027aa831cad;;2019-01-31;john.doe@test.com;;1;EUR
|
||||
64e718c9-ff99-47f1-8ca3-950c850777d4;;2019-01-30;jane.doe@test.com;;2;EUR
|
||||
7e2f2640-6866-4dcf-8f4d-3027aa831cad;;2019-01-31;ALICE;;1;EUR
|
||||
64e718c9-ff99-47f1-8ca3-950c850777d4;;2019-01-30;BOB;;2;EUR
|
||||
|
@@ -18,9 +18,12 @@
|
||||
"API_BUSINESS_PARTNER": {
|
||||
"kind": "odata",
|
||||
"model": "srv/external/API_BUSINESS_PARTNER",
|
||||
"credentials": {
|
||||
"--credentials": {
|
||||
"destination": "cap-api098"
|
||||
}
|
||||
},
|
||||
"messaging": {
|
||||
"kind": "file-based-messaging"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
6
packages/bookshop/req.http
Normal file
6
packages/bookshop/req.http
Normal file
@@ -0,0 +1,6 @@
|
||||
PATCH http://localhost:4004/api-business-partner/A_BusinessPartnerAddress(AddressID='19292',BusinessPartner='ALICE')
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"StreetName": "ChangedStreet"
|
||||
}
|
||||
@@ -1,12 +1,18 @@
|
||||
const cds = require('@sap/cds')
|
||||
const { Books } = cds.entities
|
||||
|
||||
/** Service implementation for CatalogService */
|
||||
module.exports = cds.service.impl(async function () {
|
||||
const { Books, Addresses, Orders } = this.entities
|
||||
const bupaSrv = await cds.connect.to('API_BUSINESS_PARTNER')
|
||||
this.after('READ', 'Books', each => each.stock > 111 && _addDiscount2(each, 11))
|
||||
this.before('CREATE', 'Orders', _reduceStock)
|
||||
this.on('READ', 'Addresses', req => bupaSrv.tx(req).run(req.query))
|
||||
this.after('READ', Books, each => each.stock > 111 && _addDiscount2(each, 11))
|
||||
this.before('CREATE', Orders, _reduceStock)
|
||||
this.on('READ', Addresses, req => bupaSrv.tx(req).run(req.query))
|
||||
this.on('BusinessPartner/Changed', async msg => {
|
||||
console.log('>> Received message', msg.data)
|
||||
const BUSINESSPARTNER = msg.data.KEY[0].BUSINESSPARTNER
|
||||
const orders = await cds.tx(msg).run(SELECT.from(Orders).where({ createdBy: BUSINESSPARTNER }))
|
||||
console.log(orders)
|
||||
})
|
||||
})
|
||||
|
||||
/** Add some discount for overstocked books */
|
||||
|
||||
9
packages/bookshop/srv/external/API_BUSINESS_PARTNER.js
vendored
Normal file
9
packages/bookshop/srv/external/API_BUSINESS_PARTNER.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
module.exports = srv => {
|
||||
srv.on(['CREATE', 'UPDATE', 'DELETE'], req => {
|
||||
const payload = {
|
||||
KEY: [{ BUSINESSPARTNER: req.data.BusinessPartner }]
|
||||
}
|
||||
console.log('<< Emitting message', payload)
|
||||
srv.emit('BusinessPartner/Changed', payload)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user