Browse Source

Replaced recipesFromIngredients function in Merchant class

Lee Morgan 6 years ago
parent
commit
9c590b51cd

+ 14 - 0
views/dashboardPage/Merchant.js

@@ -398,6 +398,20 @@ class Merchant{
 
         return ingredientsByCategory;
     }
+
+    getRecipesForIngredient(ingredient){
+        let recipes = [];
+
+        for(let i = 0; i < this.recipes.length; i++){
+            for(let j = 0; j < this.recipes[i].ingredients.length; j++){
+                if(this.recipes[i].ingredients[j].ingredient === ingredient){
+                    recipes.push(this.recipes[i]);
+                }
+            }
+        }
+
+        return recipes;
+    }
 }
 
 class Order{

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

@@ -575,7 +575,9 @@ let ingredientDetailsComp = {
         document.querySelector("#dailyUse").innerText = `${(sum/quantities.length).toFixed(2)} ${ingredient.ingredient.unit}`;
 
         let ul = document.querySelector("#ingredientRecipeList");
-        let recipes = recipesForIngredient(ingredient.id);
+        console.log(ingredient);
+        let recipes = merchant.getRecipesForIngredient(ingredient.ingredient);
+        console.log(recipes);
         while(ul.children.length > 0){
             ul.removeChild(ul.firstChild);
         }

+ 0 - 15
views/dashboardPage/controller.js

@@ -286,19 +286,4 @@ let categorizeIngredientsFromDB = (ingredients)=>{
     return ingredientsByCategory;
 }
 
-let recipesForIngredient = (ingredientId)=>{
-    let recipes = [];
-
-    for(let i = 0; i < merchant.recipes.length; i++){
-        for(let j = 0; j < merchant.recipes[i].ingredients.length; j++){
-            if(merchant.recipes[i].ingredients[j].ingredient._id === ingredientId){
-                recipes.push(merchant.recipes[i]);
-                break;
-            }
-        }
-    }
-
-    return recipes;
-}
-
 homeStrandObj.display();