Explorar el Código

Fix bug when removing ingredient from recipe

Lee Morgan hace 6 años
padre
commit
aede241f00
Se han modificado 2 ficheros con 13 adiciones y 11 borrados
  1. 1 1
      controllers/merchantData.js
  2. 12 10
      views/recipesPage/singleRecipe.js

+ 1 - 1
controllers/merchantData.js

@@ -578,7 +578,7 @@ module.exports = {
 
                 recipe.save()
                     .then((recipe)=>{
-                        return res.json();
+                        return res.json({});
                     })
                     .catch((err)=>{
                         let errorMessage = "There was an error and the ingredient could not be remove from the recipe";

+ 12 - 10
views/recipesPage/singleRecipe.js

@@ -131,22 +131,24 @@ let singleRecipeObj = {
     //Delete ingredient from table
     //Delete ingredient from database
     deleteIngredient: function(recipeId, ingredientId, row){
-        row.parentNode.removeChild(row);
-
-        let updateRecipe = merchant.recipes.find(r => r._id === recipeId);
-        for(let i = 0; i < updateRecipe.ingredients.length; i++){
-            if(updateRecipe.ingredients[i]._id === ingredientId){
-                updateRecipe.ingredients.splice(i, 1);
-                break;
-            }
-        }
+        
         
         axios.post("/merchant/recipes/ingredients/remove", {ingredientId: ingredientId, recipeId: recipeId})
             .then((result)=>{
                 if(typeof(result.data) === "string"){
                     banner.createError(result.data);
                 }else{
-                    banner.createNotification("Ingredient has been removed from recipe");
+                    row.parentNode.removeChild(row);
+
+                    let updateRecipe = merchant.recipes.find(r => r._id === recipeId);
+                    for(let i = 0; i < updateRecipe.ingredients.length; i++){
+                        if(updateRecipe.ingredients[i]._id === ingredientId){
+                            updateRecipe.ingredients.splice(i, 1);
+                            break;
+                        }
+                    }
+
+                    recipesObj.isPopulated = false;
                 }
             })
             .catch((err)=>{