Pārlūkot izejas kodu

Update ingredients on transaction removal on frontend

Lee Morgan 5 gadi atpakaļ
vecāks
revīzija
6aeec3fd11

+ 0 - 1
controllers/orderData.js

@@ -166,7 +166,6 @@ module.exports = {
 
                 for(let i = 0; i < order.ingredients.length; i++){
                     for(let j = 0; j < merchant.inventory.length; j++){
-                        
                         if(order.ingredients[i].ingredient.toString() === merchant.inventory[j].ingredient.toString()){
                             merchant.inventory[j].quantity -= order.ingredients[i].quantity;
                             break;

+ 11 - 1
views/dashboardPage/bundle.js

@@ -2929,7 +2929,17 @@ let transactionDetails = {
                 if(typeof(response) === "string"){
                     banner.createError(response);
                 }else{
-                    merchant.editTransactions(this.transaction, true);
+                    let ingredients = {};
+                    for(let i = 0; i < this.transaction.recipes.length; i++){
+                        let recipe = this.transaction.recipes[i];
+                        for(let j = 0; j < recipe.recipe.ingredients.length; j++){
+                            ingredient = recipe.recipe.ingredients[j];
+
+                            ingredients[ingredient.ingredient.id] = ingredient.quantity * recipe.quantity;
+                        }
+                    }
+
+                    merchant.editTransactions(this.transaction, ingredients, true);
                     banner.createNotification("TRANSACTION REMOVED");
                 }
             })

+ 11 - 1
views/dashboardPage/js/transactionDetails.js

@@ -55,7 +55,17 @@ let transactionDetails = {
                 if(typeof(response) === "string"){
                     banner.createError(response);
                 }else{
-                    merchant.editTransactions(this.transaction, true);
+                    let ingredients = {};
+                    for(let i = 0; i < this.transaction.recipes.length; i++){
+                        let recipe = this.transaction.recipes[i];
+                        for(let j = 0; j < recipe.recipe.ingredients.length; j++){
+                            ingredient = recipe.recipe.ingredients[j];
+
+                            ingredients[ingredient.ingredient.id] = ingredient.quantity * recipe.quantity;
+                        }
+                    }
+
+                    merchant.editTransactions(this.transaction, ingredients, true);
                     banner.createNotification("TRANSACTION REMOVED");
                 }
             })