some more cosmetics tweaks
This commit is contained in:
@@ -50,22 +50,17 @@ bupa.on ('BusinessPartner/Changed', async (msg) => {
|
|||||||
const { SELECT, UPDATE } = cds.ql(msg) //> convenient alternative to <srv>.transaction(req).run(SELECT...)
|
const { SELECT, UPDATE } = cds.ql(msg) //> convenient alternative to <srv>.transaction(req).run(SELECT...)
|
||||||
|
|
||||||
// fetch affected entries from local replicas
|
// fetch affected entries from local replicas
|
||||||
const local = db.transaction (msg)
|
|
||||||
const replicas = await SELECT.from (Addresses) .where ({BusinessPartner})
|
const replicas = await SELECT.from (Addresses) .where ({BusinessPartner})
|
||||||
|
if (replicas.length === 0) return //> not affected
|
||||||
// skip if not affected
|
|
||||||
if (replicas.length === 0) return
|
|
||||||
|
|
||||||
// fetch changed data from S/4 -> might be less than local due to deletes
|
// fetch changed data from S/4 -> might be less than local due to deletes
|
||||||
const changed = await SELECT.from (externalAddresses) .where ({
|
const changed = await SELECT.from (externalAddresses) .where ({
|
||||||
BusinessPartner, ID: replicas.map(a => a.ID) // where in
|
BusinessPartner, ID: replicas.map(a => a.ID) // where in
|
||||||
})
|
})
|
||||||
|
|
||||||
// update local replicas with changes from remote
|
// update local replicas with changes from S/4
|
||||||
return local.run (changed.map (a =>
|
const local = db.transaction (msg) //> using that variant to benefit from bulk runs
|
||||||
UPDATE (Addresses) .with(a) .where ({ ID: a.ID })
|
return local.run (changed.map (a => UPDATE (Addresses,a.ID) .with (a) ))
|
||||||
))
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user