Jelajahi Sumber

Fix creating new ingredients

Lee Morgan 6 tahun lalu
induk
melakukan
843f647cbe

+ 6 - 8
views/dashboardPage/Merchant.js

@@ -99,14 +99,11 @@ class Merchant{
     /*
     Updates all specified item in the merchant's inventory and updates the page
     If ingredient doesn't exist, add it
-    Inputs:
-    Array of objects
-        id: id of ingredient
-        quantity: change in quantity (if not removing)
-        name: name of ingredient (only for new ingredient)
-        category: category of ingredient (only for new ingredient)
-        unit: unit of measurement (only for new ingredient)
-    remove: if true, remove ingredient from inventory
+    ingredients = {
+        ingredient: Ingredient object,
+        quantity: change in quantity
+    }
+    remove = set true if removing
     */
     addIngredients(ingredients, remove = false){
         for(let i = 0; i < ingredients.length; i++){
@@ -132,6 +129,7 @@ class Merchant{
             }
         }
     
+        console.log("added");
         homeStrandObj.drawInventoryCheckCard();
         ingredientsStrandObj.populateByProperty("category");
         addIngredientsComp.isPopulated = false;

+ 10 - 3
views/dashboardPage/components/components.js

@@ -288,7 +288,16 @@ let newIngredientComp = {
                     if(typeof(response) === "string"){
                         banner.createError(response);
                     }else{
-                        updateInventory([response]);
+                        merchant.addIngredients([{
+                            ingredient: new Ingredient(
+                                response.ingredient._id,
+                                response.ingredient.name,
+                                response.ingredient.category,
+                                response.ingredient.unit
+                            ),
+                            quantity: response.quantity
+                        }]);
+
                         banner.createNotification("Ingredient successfully created");
                     }
                 })
@@ -539,7 +548,6 @@ let addIngredientsComp = {
                 }
             })
             .catch((err)=>{
-                console.log(err);
                 banner.createError("Something went wrong.  Try refreshing the page");
             });
     }
@@ -654,7 +662,6 @@ let ingredientDetailsComp = {
                     }
                 })
                 .catch((err)=>{
-                    console.log(err);
                     banner.createError("Something went wrong, try refreshing the page");
                 });
         }

+ 0 - 3
views/dashboardPage/ingredients.js

@@ -11,10 +11,8 @@ window.ingredientsStrandObj = {
     },
 
     populateByProperty: function(property){
-        console.log("populate by property");
         let categories;
         if(property === "category"){
-            console.log("categorizing");
             categories = merchant.categorizeIngredients();
         }else if(property === "unit"){
             categories = unitizeIngredients(merchant.inventory);
@@ -51,7 +49,6 @@ window.ingredientsStrandObj = {
             }
         }
 
-        console.log("done");
     },
 
     displayIngredientsOnly: function(ingredients){