messaging
This commit is contained in:
@@ -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