This commit is contained in:
D065023
2020-01-28 09:07:23 +01:00
parent 04ab69c48f
commit e042317f82
4 changed files with 23 additions and 2 deletions

View File

@@ -14,7 +14,10 @@
"requires": {
"API_BUSINESS_PARTNER": {
"kind": "odata",
"model": "srv/external/API_BUSINESS_PARTNER"
"model": "srv/external/API_BUSINESS_PARTNER",
"credentials": {
"destination": "API098"
}
}
}
}

View File

@@ -1,4 +1,5 @@
using { sap.capire.bookshop as my } from '../db/schema';
using { API_BUSINESS_PARTNER.A_BusinessPartnerAddress } from './external/API_BUSINESS_PARTNER.csn';
@path:'/browse'
service CatalogService {
@@ -7,6 +8,15 @@ service CatalogService {
author.name as author
} excluding { createdBy, modifiedBy };
@readonly entity Addresses as projection on A_BusinessPartnerAddress {
key AddressID,
key BusinessPartner,
StreetName,
CityName,
HouseNumber,
Country
};
@requires_: 'authenticated-user'
@insertonly entity Orders as projection on my.Orders;

View File

@@ -2,9 +2,12 @@ const cds = require('@sap/cds')
const { Books } = cds.entities
/** Service implementation for CatalogService */
module.exports = cds.service.impl(function() {
module.exports = cds.service.impl(async function() {
const bupaSrv = await cds.connect.to('API_BUSINESS_PARTNER')
const { A_BusinessPartnerAddress } = bupaSrv.entities
this.after ('READ', 'Books', each => each.stock > 111 && _addDiscount2(each,11))
this.before ('CREATE', 'Orders', _reduceStock)
this.on('READ', 'Addresses', req => bupaSrv.run(req.query.from(A_BusinessPartnerAddress)))
})
/** Add some discount for overstocked books */

View File

@@ -0,0 +1,5 @@
BusinessPartner;AddressID;CityName;PostalCode;Country;StreetName;HouseNumber
ALICE;62640;Walldorf;69190;GER;Dietmer-Hopp-Allee;16
ALICE;62641;Berlin;69390;GER;Berlin-Street;19
BOB;62341;Karlsruhe;61390;GER;Karlsruhe-Street;19
anonymous;61321;Sometown;61290;GER;Sometown-Street;19
1 BusinessPartner AddressID CityName PostalCode Country StreetName HouseNumber
2 ALICE 62640 Walldorf 69190 GER Dietmer-Hopp-Allee 16
3 ALICE 62641 Berlin 69390 GER Berlin-Street 19
4 BOB 62341 Karlsruhe 61390 GER Karlsruhe-Street 19
5 anonymous 61321 Sometown 61290 GER Sometown-Street 19