Mocking events from SAP S/4HANA
This commit is contained in:
11
suppliers/srv/external/API_BUSINESS_PARTNER.js
vendored
Normal file
11
suppliers/srv/external/API_BUSINESS_PARTNER.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
const cds = require("@sap/cds");
|
||||||
|
|
||||||
|
module.exports = cds.service.impl(function () {
|
||||||
|
const { A_BusinessPartner } = this.entities;
|
||||||
|
|
||||||
|
this.after("UPDATE", A_BusinessPartner, (data, req) =>
|
||||||
|
this.tx(req).emit("BusinessPartner.Changed", {
|
||||||
|
BusinessPartner: data.BusinessPartner
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
@@ -53,3 +53,12 @@ annotate S4.Suppliers with @cds.persistence:{table,skip:false};
|
|||||||
extend projection CatalogService.ListOfBooks with {
|
extend projection CatalogService.ListOfBooks with {
|
||||||
supplier.name as supplier
|
supplier.name as supplier
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Extend S4 service with modeled event
|
||||||
|
extend service S4 {
|
||||||
|
@type: 'sap.s4.beh.businesspartner.v1.BusinessPartner.Changed.v1'
|
||||||
|
event BusinessPartner.Changed {
|
||||||
|
BusinessPartner: S4.A_BusinessPartner:BusinessPartner;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,9 +35,9 @@ module.exports = async()=>{ // called by server.js
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Subscribe to changes in the S4 origin of Suppliers data
|
// Subscribe to changes in the S4 origin of Suppliers data
|
||||||
S4bupa.on ('BusinessPartners/Changed', async msg => { //> would be great if we had batch events from S/4
|
S4bupa.on ('BusinessPartner.Changed', async msg => { //> would be great if we had batch events from S/4
|
||||||
let replicas = await SELECT('ID').from (Suppliers) .where ('ID in', msg.businessPartners)
|
let replica = await SELECT.one('ID').from (Suppliers) .where ({ID: msg.data.BusinessPartner})
|
||||||
return replicate (replicas.map(each => each.ID))
|
return replicate (replica.ID)
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user