This commit is contained in:
Koch
2022-10-19 15:38:28 +02:00
parent bf0587b028
commit cae6a21b89
17 changed files with 20 additions and 532 deletions

View File

@@ -3,8 +3,8 @@ using { sap.capire.performance as my } from '../db/schema';
service PerformanceService {
entity OrdersHeaders as projection on my.OrdersHeaders;
entity OrdersItems as projection on my.OrdersItems;
entity Books as projection on my.Books;
entity Authors as projection on my.Authors;
entity Books as projection on my.Books;
entity Authors as projection on my.Authors;
// static
view OrdersItemsViewJoin as select
@@ -66,7 +66,7 @@ from OrdersItems {*, Header.OrderNo, Header.buyer, Header.currency }
where OrdersItems.price > 100;
// TODO avoid CASE and/or JOIN: Denormalization of expensive complex structures,
// TODO avoid CASE -- Denormalization of expensive complex structures,
// calculate on write instead of read
// CASE -> try to remodel to avoid CASE, if re-modelling is not possible,
@@ -82,6 +82,14 @@ entity OrdersItemsCaseView as projection on OrdersItems {
};
extend my.OrdersItems with {
itemCategory: String enum{ Small; Medium; Large;};
// fill itemCategory at runtime in performance-service.js
}
entity OrdersItemsNoCaseView as projection on OrdersItems {
*,
itemCategory as category
};
}

View File

@@ -5,6 +5,14 @@ class OrdersService extends cds.ApplicationService {
init(){
const { 'Orders.Items':OrderItems } = this.entities
// fill itemCategory at runtime
this.before (['CREATE', 'UPDATE'], async req =>{
if(req.data.quantity > 500) {req.data.itemCategory = 'Large'}
else if (req.data.quantity > 100) {req.data.itemCategory = 'Medium'}
else {req.data.itemCategory = 'Small'}
})
//
this.before ('UPDATE', 'Orders', async function(req) {
const { ID, Items } = req.data
if (Items) for (let { product_ID, quantity } of Items) {