Compare commits
7 Commits
openSAP-we
...
openSAP-we
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b9ee0f827 | ||
|
|
b75a47c6ef | ||
|
|
8055848430 | ||
|
|
a6e9fac097 | ||
|
|
e33fb7df0b | ||
|
|
e2aac07054 | ||
|
|
e6ab102512 |
@@ -11,7 +11,7 @@ In SAP Business Application Studio, open a terminal.
|
||||
Then clone the repo with this specific branch:
|
||||
|
||||
```sh
|
||||
git clone https://github.com/sap-samples/cloud-cap-samples projects/cloud-cap-samples -b openSAP-week4-unit2-final
|
||||
git clone https://github.com/sap-samples/cloud-cap-samples projects/cloud-cap-samples -b openSAP-week4-unit3-final
|
||||
cd projects/cloud-cap-samples
|
||||
```
|
||||
|
||||
|
||||
@@ -20,8 +20,12 @@
|
||||
"kind": "odata",
|
||||
"model": "srv/external/API_BUSINESS_PARTNER",
|
||||
"--credentials": {
|
||||
"prefix": "sap/S4HANAOD/c098/BO",
|
||||
"destination": "cap-api098"
|
||||
}
|
||||
},
|
||||
"--messaging": {
|
||||
"kind": "enterprise-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_BusinessPartner('ALICE')
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"BusinessPartnerIsBlocked": true
|
||||
}
|
||||
@@ -16,6 +16,10 @@ service CatalogService {
|
||||
BusinessPartnerIsBlocked
|
||||
};
|
||||
|
||||
event OrderBlocked {
|
||||
ID: UUID;
|
||||
};
|
||||
|
||||
@requires_: 'authenticated-user'
|
||||
@insertonly entity Orders as projection on my.Orders;
|
||||
|
||||
|
||||
@@ -8,6 +8,19 @@ module.exports = cds.service.impl(async function () {
|
||||
this.before('CREATE', Orders, _reduceStock)
|
||||
this.on('READ', BusinessPartners, req => bupaSrv.tx(req).run(req.query))
|
||||
|
||||
/** Block orders if business partner is blocked */
|
||||
bupaSrv.on('BusinessPartner/Changed', async msg => {
|
||||
console.log('>> Received BusinessPartner/Changed', msg.data)
|
||||
const BUSINESSPARTNER = msg.data.KEY[0].BUSINESSPARTNER
|
||||
const tx = cds.tx(msg)
|
||||
const orders = await tx.run(SELECT('ID').from(Orders).where({ createdBy: BUSINESSPARTNER, status: 'processing' }))
|
||||
if (!orders.length) return
|
||||
const businessPartner = await bupaSrv.tx(msg).run(SELECT.one('BusinessPartnerIsBlocked').from(BusinessPartners).where({ ID: BUSINESSPARTNER }))
|
||||
if (!businessPartner || !businessPartner.BusinessPartnerIsBlocked) return
|
||||
await Promise.all(orders.map(order => tx.run(UPDATE(Orders).where(order).set({ status: 'blocked' }))))
|
||||
orders.forEach(order => this.emit('OrderBlocked', order) && console.log('>> Emitted OrderBlocked', order))
|
||||
})
|
||||
|
||||
/** Add some discount for overstocked books */
|
||||
function _addDiscount2(each, discount) {
|
||||
each.title += ` -- ${discount}% discount!`
|
||||
|
||||
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 }]
|
||||
}
|
||||
srv.emit('BusinessPartner/Changed', payload)
|
||||
console.log('<< Emitted BusinessPartner/Changed', payload)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user