@@ -7,30 +7,30 @@ class OrdersService extends cds.ApplicationService {
77
88 this . before ( 'UPDATE' , 'Orders' , async function ( req ) {
99 const { ID , Items } = req . data
10- if ( Items ) for ( let { product_ID, amount } of Items ) {
11- const { amount :before } = await cds . tx ( req ) . run (
12- SELECT . one . from ( OrderItems , oi => oi . amount ) . where ( { up__ID :ID , product_ID} )
10+ if ( Items ) for ( let { product_ID, quantity } of Items ) {
11+ const { quantity :before } = await cds . tx ( req ) . run (
12+ SELECT . one . from ( OrderItems , oi => oi . quantity ) . where ( { up__ID :ID , product_ID} )
1313 )
14- if ( amount != before ) await this . orderChanged ( product_ID , amount - before )
14+ if ( quantity != before ) await this . orderChanged ( product_ID , quantity - before )
1515 }
1616 } )
1717
1818 this . before ( 'DELETE' , 'Orders' , async function ( req ) {
1919 const { ID } = req . data
2020 const Items = await cds . tx ( req ) . run (
21- SELECT . from ( OrderItems , oi => { oi . product_ID , oi . amount } ) . where ( { up__ID :ID } )
21+ SELECT . from ( OrderItems , oi => { oi . product_ID , oi . quantity } ) . where ( { up__ID :ID } )
2222 )
23- if ( Items ) await Promise . all ( Items . map ( it => this . orderChanged ( it . product_ID , - it . amount ) ) )
23+ if ( Items ) await Promise . all ( Items . map ( it => this . orderChanged ( it . product_ID , - it . quantity ) ) )
2424 } )
2525
2626 return super . init ( )
2727 }
2828
2929 /** order changed -> broadcast event */
30- orderChanged ( product , deltaAmount ) {
30+ orderChanged ( product , deltaQuantity ) {
3131 // Emit events to inform subscribers about changes in orders
32- console . log ( '> emitting:' , 'OrderChanged' , { product, deltaAmount } )
33- return this . emit ( 'OrderChanged' , { product, deltaAmount } )
32+ console . log ( '> emitting:' , 'OrderChanged' , { product, deltaQuantity } )
33+ return this . emit ( 'OrderChanged' , { product, deltaQuantity } )
3434 }
3535
3636}
0 commit comments