address -> bupa
This commit is contained in:
@@ -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