address -> bupa
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
ID;modifiedAt;createdAt;createdBy;modifiedBy;OrderNo;currency_code
|
||||
7e2f2640-6866-4dcf-8f4d-3027aa831cad;;2019-01-31;ALICE;;1;EUR
|
||||
7f2f2640-6866-4dcf-8f4d-3027aa831cad;;2019-03-25;ALICE;;10;EUR
|
||||
da86efd0-4ba1-4078-b7f0-5c9c530297f7;;2019-01-31;ALICE;;1;EUR
|
||||
2f2f2640-6866-4dcf-8f4d-3027aa831cad;;2019-03-25;ALICE;;10;EUR
|
||||
64e718c9-ff99-47f1-8ca3-950c850777d4;;2019-01-30;BOB;;2;EUR
|
||||
|
@@ -19,15 +19,13 @@
|
||||
"API_BUSINESS_PARTNER": {
|
||||
"kind": "odata",
|
||||
"model": "srv/external/API_BUSINESS_PARTNER",
|
||||
"credentials": {
|
||||
"--credentials": {
|
||||
"prefix": "sap/S4HANAOD/c098/BO",
|
||||
"destination": "cap-api098"
|
||||
}
|
||||
},
|
||||
"messaging": {
|
||||
"kind": "enterprise-messaging",
|
||||
"credentials": {
|
||||
"prefix": "sap/S4HANAOD/c098/BO"
|
||||
}
|
||||
"--messaging": {
|
||||
"kind": "enterprise-messaging"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
PATCH http://localhost:4004/api-business-partner/A_BusinessPartnerAddress(AddressID='19292',BusinessPartner='ALICE')
|
||||
PATCH http://localhost:4004/api-business-partner/A_BusinessPartner('ALICE')
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"StreetName": "ChangedStreet"
|
||||
}
|
||||
"IsMarkedForArchiving": true
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using { sap.capire.bookshop as my } from '../db/schema';
|
||||
using { API_BUSINESS_PARTNER.A_BusinessPartnerAddress } from './external/API_BUSINESS_PARTNER.csn';
|
||||
using { API_BUSINESS_PARTNER as external } from './external/API_BUSINESS_PARTNER.csn';
|
||||
|
||||
@path:'/browse'
|
||||
service CatalogService {
|
||||
@@ -8,17 +8,15 @@ service CatalogService {
|
||||
author.name as author
|
||||
} excluding { createdBy, modifiedBy };
|
||||
|
||||
@readonly entity Addresses as projection on A_BusinessPartnerAddress {
|
||||
key AddressID as ID,
|
||||
key BusinessPartner,
|
||||
StreetName,
|
||||
HouseNumber,
|
||||
CityName,
|
||||
PostalCode,
|
||||
Country
|
||||
@readonly entity BusinessPartners as projection on external.A_BusinessPartner {
|
||||
key BusinessPartner as ID,
|
||||
FirstName,
|
||||
MiddleName,
|
||||
LastName,
|
||||
IsMarkedForArchiving
|
||||
};
|
||||
|
||||
event OrderOutdated {
|
||||
event OrderMadeObsolete {
|
||||
ID: UUID;
|
||||
};
|
||||
|
||||
|
||||
@@ -2,16 +2,22 @@ const cds = require('@sap/cds')
|
||||
|
||||
/** Service implementation for CatalogService */
|
||||
module.exports = cds.service.impl(async function () {
|
||||
const { Books, Addresses, Orders } = this.entities
|
||||
const { Books, Orders, BusinessPartners } = this.entities
|
||||
const bupaSrv = await cds.connect.to('API_BUSINESS_PARTNER')
|
||||
this.after('READ', Books, each => each.stock > 111 && _addDiscount2(each, 11))
|
||||
this.before('CREATE', Orders, _reduceStock)
|
||||
this.on('READ', Addresses, req => bupaSrv.tx(req).run(req.query))
|
||||
this.on('READ', BusinessPartners, req => bupaSrv.tx(req).run(req.query))
|
||||
|
||||
bupaSrv.on('BusinessPartner/Changed', async msg => {
|
||||
console.log('>> Received message', msg.data)
|
||||
console.log('>> Received', msg.data)
|
||||
const BUSINESSPARTNER = msg.data.KEY[0].BUSINESSPARTNER
|
||||
const orders = await cds.tx(msg).run(SELECT('ID').from(Orders).where({ createdBy: BUSINESSPARTNER }))
|
||||
orders.forEach(order => this.emit('OrderOutdated', order) && console.log('<< Emitting message', order))
|
||||
if (orders.length) {
|
||||
const businessPartner = await bupaSrv.tx(msg).run(SELECT.one(BusinessPartners).where({ ID: BUSINESSPARTNER }))
|
||||
if (businessPartner.IsMarkedForArchiving) {
|
||||
orders.forEach(order => this.emit('OrderMadeObsolete', order) && console.log('>> Emitted', order))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
/** Add some discount for overstocked books */
|
||||
|
||||
@@ -3,7 +3,7 @@ module.exports = srv => {
|
||||
const payload = {
|
||||
KEY: [{ BUSINESSPARTNER: req.data.BusinessPartner }]
|
||||
}
|
||||
console.log('<< Emitting message', payload)
|
||||
srv.emit('BusinessPartner/Changed', payload)
|
||||
console.log('<< Emitted', payload)
|
||||
})
|
||||
}
|
||||
4
packages/bookshop/srv/external/data/API_BUSINESS_PARTNER-A_BusinessPartner.csv
vendored
Normal file
4
packages/bookshop/srv/external/data/API_BUSINESS_PARTNER-A_BusinessPartner.csv
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
BusinessPartner;FirstName;MiddleName;LastName;IsMarkedForArchiving
|
||||
ALICE;Alice;In;Wonderland;false
|
||||
BOB;Bob;The;Builder;false
|
||||
JABBA;Jabba;The;Hutt;true
|
||||
|
@@ -1,6 +0,0 @@
|
||||
BusinessPartner;AddressID;CityName;PostalCode;Country;StreetName;HouseNumber
|
||||
ALICE;19292;Walldorf;69190;GER;Dietmer-Hopp-Allee;16
|
||||
ALICE;93719;Walldorf;69190;GER;Hasso-Plattner-Ring;7
|
||||
ALICE;92939;St.Leon-Rot;68789;GER;SAP-Allee;29
|
||||
BOB;92786;Dresden;00187;GER;Chemnitzer Str.;48
|
||||
BOB;92840;Dresden;01067;GER;Postplatz;1
|
||||
|
Reference in New Issue
Block a user