cleaned up

This commit is contained in:
Daniel
2019-12-21 18:01:58 +01:00
parent 421cea9f2b
commit 45843ab7bd
2 changed files with 20 additions and 40 deletions

View File

@@ -1,11 +1,9 @@
const utils = require('./utils')
const cds = require('@sap/cds')
module.exports = cds.service.impl (async ()=>{
module.exports = cds.service.impl (async()=>{
// We are mashing up three services...
const admin = await cds.connect.to ('AdminService')
const bupa = await cds.connect.to ('API_BUSINESS_PARTNER')
const admin = await cds.connect.to ('AdminService')
const db = await cds.connect.to ('db')
// Using reflected definitions from connected services/database
@@ -15,9 +13,9 @@ 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) => {
const UsersAddresses = req.query.from (externalAddresses) .where ({ contact: req.user.id || 'anonymous' })
//> redirecting the incoming query with req.query.from preserves all .columns and .where clauses
return bupa.tx(req) .read (UsersAddresses)
console.log ('Delegating to S/4 bupa service...')
const UsersAddresses = SELECT.from (externalAddresses) .where ({ contact: req.user.id || 'anonymous' })
return bupa.tx(req) .run (UsersAddresses.where (req.query.SELECT.where))
})
@@ -81,3 +79,4 @@ module.exports = cds.service.impl (async ()=>{
})
})
require('./utils') // ugly workaround for AppStudio

View File

@@ -16,56 +16,37 @@ extend service API_BUSINESS_PARTNER with {
PostalCode as postalCode,
StreetName as streetName,
HouseNumber as houseNumber
};
}
/**
* Re-modelling the event which is currently not available declaratively from S/4
*/
// @messaging.topic:'${prefix}/BusinessPartner/Changed'
// event "BusinessPartner/Changed" {
// "KEY": array of {
// BUSINESSPARTNER : external.A_BusinessPartner.BusinessPartner
// }
// }
entity BusinessPartner as projection on external.A_BusinessPartner;
@messaging.topic:'${prefix}/BusinessPartner/Changed'
event BusinessPartner_CHANGED {
_KEY: array of {
BUSINESSPARTNER : external.A_BusinessPartner.BusinessPartner
}
}
}
/**
* Mashup w/ services to also serve shipping addresses
*/
// using { AdminService } from './admin-service';
// extend service AdminService { // for ValueHelps from S/4 backend
// @readonly entity usersAddresses as projection on external.Addresses;
// }
// // TODO: not used so far...
// using { CatalogService } from './cat-service';
// extend service CatalogService { // for ValueHelps from S/4 backend
// @requires:'authenticated-user'
// @readonly entity usersAddresses as projection on external.Addresses;
// }
// have external Addresses auto-exposed as targets
annotate external.Addresses with @cds.autoexpose;
/**
* Mashup w/ domain model for federated data access
*/
using { sap.capire.bookshop } from '../db/schema';
/**
* Add an entity to replicate external address data for quick access,
* e.g. when displaying lists of orders.
*/
@cds.persistence:{table,skip:false}
@cds.persistence:{table,skip:false} //> create a table with the view's inferred signature
@cds.autoexpose //> auto-expose in services as targets for ValueHelps and joins
entity sap.capire.bookshop.Addresses as SELECT from external.Addresses { *,
false as tombstone : Boolean
};
/**
* Extend Orders to with references to replicated external Addresses
* Extend Orders with references to replicated external Addresses
*/
using { sap.capire.bookshop } from '../db/schema';
extend bookshop.Orders with {
shippingAddress : Association to bookshop.Addresses;
}