Pārlūkot izejas kodu

Update orderData.js to handle new bottle structure.

Lee Morgan 5 gadi atpakaļ
vecāks
revīzija
65baad2814
1 mainītis faili ar 7 papildinājumiem un 16 dzēšanām
  1. 7 16
      controllers/orderData.js

+ 7 - 16
controllers/orderData.js

@@ -237,22 +237,13 @@ module.exports = {
                     let exists = false;
                     for(let j = 0; j < merchant.inventory.length; j++){
                         if(merchant.inventory[j].ingredient.name.toLowerCase() === array[i][locations.ingredients].toLowerCase()){
-                            let baseQuantity = 0;
-                            if(merchant.inventory[j].ingredient.specialUnit === "bottle"){
-                                baseQuantity = array[i][locations.quantity];
-                                order.ingredients.push({
-                                    ingredient: merchant.inventory[j].ingredient._id,
-                                    quantity: baseQuantity,
-                                    pricePerUnit: (array[i][locations.price] * 100) / merchant.inventory[j].ingredient.unitSize
-                                });
-                            }else{
-                                baseQuantity = helper.convertQuantityToBaseUnit(array[i][locations.quantity], merchant.inventory[j].defaultUnit);
-                                order.ingredients.push({
-                                    ingredient: merchant.inventory[j].ingredient._id,
-                                    quantity: baseQuantity,
-                                    pricePerUnit: helper.convertPrice(array[i][locations.price] * 100, merchant.inventory[j].defaultUnit)
-                                });
-                            }
+                            let baseQuantity = helper.convertQuantityToBaseUnit(array[i][locations.quantity], merchant.inventory[j].defaultUnit);
+                            order.ingredients.push({
+                                ingredient: merchant.inventory[j].ingredient._id,
+                                quantity: baseQuantity,
+                                //TODO: this should not be storing based on the default unit, but the base unit
+                                pricePerUnit: helper.convertPrice(array[i][locations.price] * 100, merchant.inventory[j].defaultUnit)
+                            });
 
                             merchant.inventory[j].quantity += baseQuantity;