Forráskód Böngészése

Fix removeRecipeIngredients function in back end

Lee Morgan 6 éve
szülő
commit
ae6b0416fa
1 módosított fájl, 5 hozzáadás és 7 törlés
  1. 5 7
      controllers/home.js

+ 5 - 7
controllers/home.js

@@ -359,18 +359,16 @@ module.exports = {
             return res.render("error");
         }
 
-        Merchant.findOne({_id: req.session.user})
-            .then((merchant)=>{
-                let recipe = merchant.recipes.find(r => r._id.toString() === req.body.recipeId);
+        Recipe.findOne({_id: req.body.recipeId})
+            .then((recipe)=>{
                 for(let i = 0; i < recipe.ingredients.length; i++){
-                    if(req.body.ingredientId === recipe.ingredients[i]._id.toString()){
+                    if(recipe.ingredients[i]._id.toString() === req.body.ingredientId){
                         recipe.ingredients.splice(i, 1);
-                        break;
                     }
                 }
 
-                merchant.save()
-                    .then((result)=>{
+                recipe.save()
+                    .then((recipe)=>{
                         return res.json();
                     })
                     .catch((err)=>{