Suppliers moved to bookshop namespace

This commit is contained in:
Uwe Klinger
2021-05-04 08:56:20 +02:00
parent 98113c46fd
commit 8601bd8a46
7 changed files with 67 additions and 32 deletions

View File

@@ -10,9 +10,10 @@ module.exports = async()=>{ // called by server.js
const S4bupa = await cds.connect.to('API_BUSINESS_PARTNER') //> external S4 service
const admin = await cds.connect.to('AdminService') //> local domain service
const db = await cds.connect.to('db') //> our primary database
const messaging = await cds.connect.to('messaging');
// Reflect CDS definition of the Suppliers entity
const { Suppliers } = S4bupa.entities
const Suppliers = db.entities["sap.capire.bookshop.Suppliers"];
admin.prepend (()=>{ //> to ensure our .on handlers below go before the default ones
@@ -38,9 +39,9 @@ module.exports = async()=>{ // called by server.js
})
// Subscribe to changes in the S4 origin of Suppliers data
// REVISIT: cds context is still from the UPDAT method when running in same programm, but should
// REVISIT: cds context is still from the UPDATE method when running in same programm, but should
// be a separate
S4bupa.on ('BusinessPartners/Changed', async msg => { //> would be great if we had batch events from S/4
messaging.on ('BusinessPartners/Changed', async msg => { //> would be great if we had batch events from S/4
await new Promise( resolve => setTimeout( resolve, 1000 ));
const tx = cds.db.tx(msg);
let replicas = await tx.run(SELECT('ID').from (Suppliers) .where ('ID in', msg.data.businessPartners));
@@ -79,4 +80,25 @@ module.exports = async()=>{ // called by server.js
))
}
{
// one server: returns AdminSuppliers
// two servers: returns A_BusinessPartner
const tx = S4bupa.tx({});
let result = await tx.run(SELECT('*').from ('AdminService.Suppliers') .where ('ID =', 'ACME'));
tx.commit();
console.log(result);
}
{
// one server: returns AdminSuppliers
// two servers: returns AdminSuppliers
const tx = db.tx({});
let result = await db.run(SELECT('*').from ('AdminService.Suppliers') .where ('ID =', 'ACME'));
tx.commit();
console.log(result);
}
//process.exit(0);
}