浏览代码

Fix a bug in the removing of orders.

Lee Morgan 5 年之前
父节点
当前提交
3226b7e15f
共有 1 个文件被更改,包括 5 次插入4 次删除
  1. 5 4
      controllers/transactionData.js

+ 5 - 4
controllers/transactionData.js

@@ -113,15 +113,15 @@ module.exports = {
                 return Transaction.deleteOne({_id: req.params.id});
             })
             .then((response)=>{
-                res.json({});
+                res.json();
 
                 for(let i = 0; i < transaction.recipes.length; i++){
                     const recipe = transaction.recipes[i].recipe;
                     for(let j = 0; j < recipe.ingredients.length; j++){
-                        const ingredient = recipe.ingredients[i].ingredient;
+                        const ingredient = recipe.ingredients[j].ingredient;
                         for(let k = 0; k < merchant.inventory.length; k++){
-                            if(ingredient.toString() == merchant.inventory[i].ingredient.toString()){
-                                merchant.inventory[i].quantity += recipe.ingredients[i].quantity * transaction.recipes[i].quantity;
+                            if(ingredient.toString() === merchant.inventory[k].ingredient.toString()){
+                                merchant.inventory[k].quantity += recipe.ingredients[j].quantity * transaction.recipes[i].quantity;
                                 break;
                             }
                         }
@@ -131,6 +131,7 @@ module.exports = {
                 return merchant.save();
             })
             .catch((err)=>{
+                console.log(err);
                 return res.json("ERROR: UNABLE TO DELETE THE TRANSACTION");
             });
     },