소스 검색

Fix adding of ingredients to recipes

Lee Morgan 6 년 전
부모
커밋
ceb4dfaf71
1개의 변경된 파일10개의 추가작업 그리고 7개의 파일을 삭제
  1. 10 7
      controllers/home.js

+ 10 - 7
controllers/home.js

@@ -308,13 +308,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.ingredients.push(req.body.item)
-                merchant.save()
-                    .then((newMerchant)=>{
-                        return res.json(newMerchant);
+        Recipe.findOne({_id: req.body.recipeId})
+            .then((recipe)=>{
+                recipe.ingredients.push({
+                    ingredient: req.body.item.ingredient,
+                    quantity: req.body.item.quantity
+                });
+                
+                recipe.save()
+                    .then((recipe)=>{
+                        return res.json();
                     })
                     .catch((err)=>{
                         console.log(err);