Ver código fonte

Fix duplication of recipe ingredients when editing

Lee Morgan 6 anos atrás
pai
commit
a23dc8e33f

+ 8 - 0
controllers/validator.js

@@ -85,6 +85,14 @@ module.exports = {
             }
         }
 
+        for(let i = 0; i < recipe.ingredients.length; i++){
+            for(let j = i + 1; j < recipe.ingredients.length; j++){
+                if(recipe.ingredients[i].ingredient === recipe.ingredients[j].ingredient){
+                    return "Recipe cannot contain duplicate ingredients";
+                }
+            }
+        }
+
         return true;
     },
 

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

@@ -81,7 +81,7 @@ let recipeDetailsComp = {
                 this.recipe.ingredients.push({
                     ingredient: select.options[select.selectedIndex].ingredient,
                     quantity: divs[i].children[1].value
-                })
+                });
             }else{
                 this.recipe.ingredients.push({
                     ingredient: divs[i].ingredient,