diff --git a/srv/orders-service.js b/srv/orders-service.js index 222129b..b79de7e 100644 --- a/srv/orders-service.js +++ b/srv/orders-service.js @@ -8,7 +8,8 @@ class OrdersService extends cds.ApplicationService { this.before ('UPDATE', 'Orders', async function(req) { const { ID, Items } = req.data if (Items) for (let { product_ID, quantity } of Items) { - const { quantity:before } = await SELECT.one.from (OrderItems, oi => oi.quantity) .where ({up__ID:ID, product_ID}) + const { quantity:before } = (await SELECT.one.from (OrderItems, oi => oi.quantity) .where ({up__ID:ID, product_ID})) || {} + if (!before) continue if (quantity != before) await this.orderChanged (product_ID, quantity-before) } })