Skip to content

Commit ff32470

Browse files
fix: adding new items to an order should not crash
1 parent 7e49d70 commit ff32470

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

srv/orders-service.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ class OrdersService extends cds.ApplicationService {
88
this.before ('UPDATE', 'Orders', async function(req) {
99
const { ID, Items } = req.data
1010
if (Items) for (let { product_ID, quantity } of Items) {
11-
const { quantity:before } = await SELECT.one.from (OrderItems, oi => oi.quantity) .where ({up__ID:ID, product_ID})
11+
const { quantity:before } = (await SELECT.one.from (OrderItems, oi => oi.quantity) .where ({up__ID:ID, product_ID})) || {}
12+
if (!before) continue
1213
if (quantity != before) await this.orderChanged (product_ID, quantity-before)
1314
}
1415
})

0 commit comments

Comments
 (0)