瀏覽代碼

Bug fix: subingredients were undefined on the frontend.

Lee Morgan 5 年之前
父節點
當前提交
cb26ad5220
共有 2 個文件被更改,包括 21 次插入18 次删除
  1. 16 17
      views/dashboardPage/js/classes/Ingredient.js
  2. 5 1
      views/dashboardPage/js/classes/Merchant.js

+ 16 - 17
views/dashboardPage/js/classes/Ingredient.js

@@ -1,5 +1,5 @@
 class Ingredient{
-    constructor(id, name, category, unitType, unit, parent, unitSize = undefined, ingredients){
+    constructor(id, name, category, unitType, unit, parent, unitSize = undefined){
         this._id = id;
         this._name = name;
         this._category = category;
@@ -8,10 +8,6 @@ class Ingredient{
         this._parent = parent;
         this._unitSize = unitSize;
         this._ingredients = [];
-
-        for(let i = 0; i < ingredients.length; i++){
-            ingredients.push(this._parent.getIngredient(ingredinets[i]));
-        }
     }
 
     get id(){
@@ -99,20 +95,23 @@ class Ingredient{
         let volume = ["ml", "l", "tsp", "tbsp", "ozfl", "cup", "pt", "qt", "gal"];
         let length = ["mm", "cm", "m", "in", "ft"];
 
-        if(mass.includes(this._unit)){
-            return mass;
-        }
-        if(volume.includes(this._unit)){
-            return volume;
-        }
-        if(length.includes(this._unit)){
-            return length;
-        }
-        if(this._unit === "bottle"){
-            return volume;
-        }
+        if(mass.includes(this._unit)) return mass;
+        if(volume.includes(this._unit)) return volume;
+        if(length.includes(this._unit)) return length;
+        if(this._unit === "bottle") return volume;
         return [];
+    }
 
+    addIngredients(ingredients){
+        for(let i = 0; i < ingredients.length; i++){
+            // console.log(typeof(ingredients[i].ingredient));
+            // console.log(this._parent.getIngredient(ingredients[i].ingredient));
+            // console.log();
+            this._ingredients.push({
+                ingredient: this._parent.getIngredient(ingredients[i].ingredient),
+                quantity: ingredients[i].quantity
+            });
+        }
     }
 }
 

+ 5 - 1
views/dashboardPage/js/classes/Merchant.js

@@ -102,7 +102,6 @@ class Merchant{
                 ingredients[i].defaultUnit,
                 this,
                 ingredients[i].ingredient.unitSize,
-                ingredients[i].ingredient.ingredients
             );
 
             const merchantIngredient = new MerchantIngredient(
@@ -113,6 +112,11 @@ class Merchant{
             this._ingredients.push(merchantIngredient);
         }
 
+        for(let i = 0; i < ingredients.length; i++){
+            let thisIngredient = this.getIngredient(ingredients[i].ingredient._id);
+            thisIngredient.ingredient.addIngredients(ingredients[i].ingredient.ingredients);
+        }
+
         //populate recipes
         for(let i = 0; i < recipes.length; i++){
             let ingredients = [];