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