Browse Source

Allow combination of items without unit

Tatiana Inama 6 năm trước cách đây
mục cha
commit
e8aa019d9d
1 tập tin đã thay đổi với 6 bổ sung0 xóa
  1. 6 0
      recipes/src/containers/ShoppingCart/services.ts

+ 6 - 0
recipes/src/containers/ShoppingCart/services.ts

@@ -23,6 +23,12 @@ const combineItems = (a: ShoppingItem, b: ShoppingItem): ShoppingItem => {
       quantity: a.quantity + Convert(b.quantity, b.unit, a.unit, m.name as Measure)
     }
   } else {
+    if (a.quantity && b.quantity && (a.unit === 'unit' || b.unit === 'unit')) {
+      return {
+        ...a,
+        quantity: a.quantity + b.quantity
+      }
+    }
     if (a.unit !== b.unit) {
       throw Error(`cannot sum this units: ${b.unit, a.unit}`)
     } else {