Ver Fonte

Fix problem with transactions and deleted recipes.

Lee Morgan há 5 anos atrás
pai
commit
ea7c64f475

+ 15 - 0
controllers/recipeData.js

@@ -289,5 +289,20 @@ module.exports = {
                 if(err === "unauthorized") return res.json("YOU DO NOT HAVE PERMISSION TO EDIT THAT RECIPE");
                 return res.json("ERROR: UNABLE TO HIDE/UNHIDE THE RECIPE");
             });
+    },
+
+    /*
+    POST: gets a list of individual recipes
+    req.body = [String] (ids)
+    response = [Recipe]
+    */
+    findRecipes: function(req, res){
+        Recipe.find(req.body)
+            .then((recipes)=>{
+                return res.json(recipes);
+            })
+            .catch((err)=>{
+                return res.json("ERROR: UNABLE TO FIND DELETED RECIPES TO MATCH WITH TRANSACTIONS");
+            });
     }
 }

+ 0 - 1
controllers/squareData.js

@@ -272,7 +272,6 @@ module.exports = {
                 }
     
                 if(newRecipes.length > 0) Recipe.create(newRecipes);
-                if(merchantRecipes.length > 0) Recipe.deleteMany({_id: {$in: ids}});    
 
                 return res.locals.merchant.save();
             })

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

@@ -333,6 +333,16 @@ class Merchant{
         for(let i = 0; i < this._recipes.length; i++){
             if(this._recipes[i].id === id) return this._recipes[i];
         }
+
+        return new Recipe(
+            "",
+            "Deleted Recipe",
+            "",
+            0,
+            [],
+            undefined,
+            true
+        );
     }
 
     /*

+ 1 - 1
views/dashboardPage/js/classes/Transaction.js

@@ -1,6 +1,6 @@
 class TransactionRecipe{
     constructor(recipe, quantity, merchant){
-        this._recipe = merchant.getRecipe(recipe);
+        this._recipe = merchant.getRecipe(recipe, true);
         this._quantity = quantity;
     }