made async api work

This commit is contained in:
D065023
2019-12-23 15:54:52 +01:00
parent 5b5d9da82e
commit fdd0a256c4
3 changed files with 20 additions and 17 deletions

View File

@@ -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"
}
}
},

View File

@@ -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' })

View File

@@ -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