made async api work
This commit is contained in:
@@ -19,9 +19,13 @@
|
||||
"kind": "odata",
|
||||
"model": "srv/external",
|
||||
"--credentials": {
|
||||
">>": "should go to bindings !!!",
|
||||
"destination": "cap-api532",
|
||||
"prefix": "sap/S4HANAOD/c532/BO"
|
||||
"destination": "cap-api098"
|
||||
}
|
||||
},
|
||||
"--messaging": {
|
||||
"kind": "enterprise-messaging",
|
||||
"credentials": {
|
||||
"prefix": "sap/S4HANAOD/c098/BO"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -15,13 +15,11 @@ module.exports = admin => {
|
||||
// Handler to delegate ValueHelp requests to S/4 backend, fetching current user's addresses from there
|
||||
// admin.on ('READ', 'usersAddresses', (req) => { // REVISIT: all requests go to auto-exposed Addresses
|
||||
admin.on('READ', 'Addresses', req => {
|
||||
return bupa
|
||||
.tx(req)
|
||||
.run(
|
||||
SELECT.from(externalAddresses).where({
|
||||
contact: req.user.id || 'anonymous'
|
||||
})
|
||||
)
|
||||
return bupa.tx(req).run(
|
||||
SELECT.from(externalAddresses).where({
|
||||
contact: req.user.id || 'anonymous'
|
||||
})
|
||||
)
|
||||
// return bupa.tx(req) .read (externalAddresses) .where ({ contact: req.user.id || 'anonymous' }) //> FIXME: doesn't work !?!?
|
||||
// const { SELECT } = cds.ql(req) //> convenient alternative to bupa.transaction(req).run(SELECT...)
|
||||
// return SELECT.from (externalAddresses) .where ({ contact: req.user.id || 'anonymous' })
|
||||
|
||||
@@ -12,9 +12,11 @@ module.exports = cds.service.impl(async () => {
|
||||
// Delegate ValueHelp requests to S/4 backend, fetching current user's addresses from there
|
||||
admin.on('READ', 'Addresses', req => {
|
||||
console.log('Delegating to S/4 bupa service...')
|
||||
const UsersAddresses = SELECT.from(externalAddresses).where({
|
||||
contact: req.user.id
|
||||
}).where(req.query.SELECT.where)
|
||||
const UsersAddresses = SELECT.from(externalAddresses)
|
||||
.where({
|
||||
contact: req.user.id
|
||||
})
|
||||
.where(req.query.SELECT.where)
|
||||
return bupa.tx(req).run(UsersAddresses)
|
||||
})
|
||||
|
||||
@@ -43,10 +45,9 @@ module.exports = cds.service.impl(async () => {
|
||||
if (replicas.length === 0) return //> not affected
|
||||
|
||||
// fetch changed data from S/4 -> might be less than local due to deletes
|
||||
const changed = await SELECT.from(externalAddresses).where({
|
||||
contact: BPID,
|
||||
ID: replicas.map(a => a.ID) // where in
|
||||
})
|
||||
const changed = (await SELECT.from(externalAddresses).where({
|
||||
contact: BPID
|
||||
})).filter(({ ID }) => replicas.some(rep => ID === rep.ID))
|
||||
|
||||
// update local replicas with changes from S/4
|
||||
const local = db.transaction(msg) //> using that variant to benefit from bulk runs
|
||||
|
||||
Reference in New Issue
Block a user