Compare commits
9 Commits
openSAP-we
...
openSAP-we
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f28bfbb768 | ||
|
|
7d8ca4d4a1 | ||
|
|
61aa81a806 | ||
|
|
e7c395671b | ||
|
|
cd245c4641 | ||
|
|
d081438a6a | ||
|
|
79c3a22224 | ||
|
|
9c30ad7584 | ||
|
|
c58bcf905f |
@@ -11,7 +11,7 @@ In SAP Business Application Studio, open a terminal.
|
|||||||
Then clone the repo with this specific branch:
|
Then clone the repo with this specific branch:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
git clone https://github.com/sap-samples/cloud-cap-samples projects/cloud-cap-samples -b openSAP-week4-unit3-final
|
git clone https://github.com/sap-samples/cloud-cap-samples projects/cloud-cap-samples -b openSAP-week4-unit2-final
|
||||||
cd projects/cloud-cap-samples
|
cd projects/cloud-cap-samples
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -20,12 +20,8 @@
|
|||||||
"kind": "odata",
|
"kind": "odata",
|
||||||
"model": "srv/external/API_BUSINESS_PARTNER",
|
"model": "srv/external/API_BUSINESS_PARTNER",
|
||||||
"--credentials": {
|
"--credentials": {
|
||||||
"prefix": "sap/S4HANAOD/c098/BO",
|
|
||||||
"destination": "cap-api098"
|
"destination": "cap-api098"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"--messaging": {
|
|
||||||
"kind": "enterprise-messaging"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
PATCH http://localhost:4004/api-business-partner/A_BusinessPartner('ALICE')
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{
|
|
||||||
"BusinessPartnerIsBlocked": true
|
|
||||||
}
|
|
||||||
@@ -16,10 +16,6 @@ service CatalogService {
|
|||||||
BusinessPartnerIsBlocked
|
BusinessPartnerIsBlocked
|
||||||
};
|
};
|
||||||
|
|
||||||
event OrderBlocked {
|
|
||||||
ID: UUID;
|
|
||||||
};
|
|
||||||
|
|
||||||
@requires_: 'authenticated-user'
|
@requires_: 'authenticated-user'
|
||||||
@insertonly entity Orders as projection on my.Orders;
|
@insertonly entity Orders as projection on my.Orders;
|
||||||
|
|
||||||
|
|||||||
@@ -8,19 +8,6 @@ module.exports = cds.service.impl(async function () {
|
|||||||
this.before('CREATE', Orders, _reduceStock)
|
this.before('CREATE', Orders, _reduceStock)
|
||||||
this.on('READ', BusinessPartners, req => bupaSrv.tx(req).run(req.query))
|
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 */
|
/** Add some discount for overstocked books */
|
||||||
function _addDiscount2(each, discount) {
|
function _addDiscount2(each, discount) {
|
||||||
each.title += ` -- ${discount}% discount!`
|
each.title += ` -- ${discount}% discount!`
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
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