Переглянути джерело

Prevent adding of duplicate ingredients to merchant recipes

Lee Morgan 6 роки тому
батько
коміт
09da3673d7
1 змінених файлів з 7 додано та 0 видалено
  1. 7 0
      views/recipesPage/singleRecipe.js

+ 7 - 0
views/recipesPage/singleRecipe.js

@@ -79,6 +79,13 @@ let singleRecipeObj = {
             quantity: quantity
         }
         
+        for(let ingredient of recipe.ingredients){
+            if(ingredient.ingredient._id === ingredientId){
+                banner.createError("That ingredient is already in this recipe");
+                return;
+            }
+        }
+        
         axios.post("/merchant/recipes/ingredients/create", {recipeId: recipe._id, item: item})
             .then((response)=>{
                 if(typeof(response.data) === "string"){