rm eventing
This commit is contained in:
@@ -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(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