소스 검색

Fix removeRecipeIngredients function in back end

Lee Morgan 6 년 전
부모
커밋
ae6b0416fa
1개의 변경된 파일5개의 추가작업 그리고 7개의 파일을 삭제
  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)=>{