Kaynağa Gözat

Bug fix: frontend was not updating when sub-ingredients were updated.

Lee Morgan 5 yıl önce
ebeveyn
işleme
ff174106bf

+ 1 - 2
controllers/ingredientData.js

@@ -155,7 +155,6 @@ module.exports = {
                 for(let i = 0; i < req.body.ingredients.length; i++){
                     for(let j = 0; j < res.locals.merchant.inventory.length; j++){
                         if(res.locals.merchant.inventory[j].ingredient._id.toString() === req.body.ingredients[i].ingredient){
-                            merchIngredient = res.locals.merchant.inventory[j];
                             let ingredient = res.locals.merchant.inventory[j].ingredient;
                             stack = [ingredient];
                             if(ingredient._id.toString() === req.body.id) throw "circular";
@@ -168,7 +167,7 @@ module.exports = {
                 return Promise.all([response[0].save(), res.locals.merchant.save()])
             })
             .then((response)=>{
-                return res.json(merchIngredient);
+                return res.json(response[0]);
             })
             .catch((err)=>{
                 if(err === "circular"){

+ 2 - 0
views/dashboardPage/js/classes/Merchant.js

@@ -259,9 +259,11 @@ class Merchant{
     addIngredients(ingredients){
         for(let i = 0; i < ingredients.length; i++){
             let ingredient = ingredients[i].ingredient;
+            console.log(ingredients[i]);
             let quantity = ingredients[i].quantity;
             let defaultUnit = ingredients[i].defaultUnit;
 
+            console.log(ingredient);
             const createdIngredient = new Ingredient(
                 ingredient._id,
                 ingredient.name,

+ 2 - 2
views/dashboardPage/js/modal.js

@@ -250,8 +250,7 @@ let modal = {
                             controller.createBanner(response, "error");
                         }
                     }else{
-                        merchant.removeIngredient(ingredient);
-                        merchant.addIngredients([response]);
+                        ingredient.replaceIngredients(response.ingredients);
                         state.updateIngredients();
 
                         controller.createBanner(`SUB-INGREDIENTS UPDATED FOR ${ingredient.name}`, "success");
@@ -259,6 +258,7 @@ let modal = {
                     }
                 })
                 .catch((err)=>{
+                    console.log(err);
                     controller.createBanner("SOMETHING WENT WRONG. PLEASE REFRESH THE PAGE", "error");
                 })
                 .finally(()=>{

+ 0 - 1
views/dashboardPage/js/strands/home.js

@@ -61,7 +61,6 @@ let home = {
 
         let displayCount = (merchant.inventory.length < 10) ? merchant.inventory.length : 10;
 
-        console.log(ingredients);
         for(let i = 0; i < displayCount; i++){
             if(ingredients[i].unitCost === 0) break;
             let item = document.createElement("button");