Using managed compositions for Order.Items (#273)

* Using managed compositions for Order.Items
Co-authored-by: sjvans <30337871+sjvans@users.noreply.github.com>
This commit is contained in:
Daniel Hutzel
2021-11-08 17:41:33 +01:00
committed by GitHub
parent 482b71e60b
commit 8cc2db7118
7 changed files with 16 additions and 22 deletions

View File

@@ -68,7 +68,7 @@ annotate OrdersService.Orders with @(
annotate OrdersService.Orders_Items with @(
annotate OrdersService.Orders.Items with @(
UI: {
LineItem: [
{Value: product_ID, Label:'Product ID'},

View File

@@ -3,27 +3,22 @@ namespace sap.capire.orders;
entity Orders : cuid, managed {
OrderNo : String @title:'Order Number'; //> readable key
Items : Composition of many Orders_Items on Items.up_ = $self;
Items : Composition of many {
key ID : UUID;
product : Association to Products;
quantity : Integer;
title : String; //> intentionally replicated as snapshot from product.title
price : Double; //> materialized calculated field
};
buyer : User;
currency : Currency;
}
entity Orders_Items {
key ID : UUID;
up_ : Association to Orders;
product : Association to Products;
quantity : Integer;
title : String; //> intentionally replicated as snapshot from product.title
price : Double;
}
/** This is a stand-in for arbitrary ordered Products */
entity Products @(cds.persistence.skip:'always') {
key ID : String;
}
// this is to ensure we have filled-in currencies
using from '@capire/common';

View File

@@ -2,6 +2,7 @@
"name": "@capire/orders",
"version": "1.0.0",
"dependencies": {
"@capire/common": "*",
"@sap/cds": "^5"
}
}

View File

@@ -3,7 +3,7 @@ class OrdersService extends cds.ApplicationService {
/** register custom handlers */
init(){
const { Orders_Items:OrderItems } = this.entities
const { 'Orders.Items':OrderItems } = this.entities
this.before ('UPDATE', 'Orders', async function(req) {
const { ID, Items } = req.data