瀏覽代碼

Fix broken delete ingredient button

Lee Morgan 5 年之前
父節點
當前提交
2ba8835241

+ 2 - 1
controllers/ingredientData.js

@@ -43,6 +43,7 @@ module.exports = {
         if(validation !== true){
             return res.json(validation);
         }
+
         validation = Validator.quantity(req.body.quantity);
         if(validation !== true){
             return res.json(validation);
@@ -166,7 +167,7 @@ module.exports = {
             });
     },
 
-    //POST - Removes an ingredient from the merchant's inventory
+    //DELETE - Removes an ingredient from the merchant's inventory
     removeIngredient: function(req, res){
         if(!req.session.user){
             req.session.error = "MUST BE LOGGED IN TO DO THAT";

+ 0 - 5
controllers/validator.js

@@ -75,11 +75,6 @@ module.exports = {
             return "Ingredient contains illegal characters";
         }
 
-        let quantityCheck = this.quantity(ingredient.quantity);
-            if(quantityCheck !== true){
-                return quantityCheck;
-            }
-
         if(ingredient.specialUnit === "bottle"){
             let quantityCheck = this.quantity(ingredient.unitSize);
             if(quantityCheck !== true){

+ 8 - 7
views/dashboardPage/bundle.js

@@ -2362,11 +2362,11 @@ let home = {
 module.exports = home;
 },{}],11:[function(require,module,exports){
 let ingredientDetails = {
-    ingredient: {},
     dailyUse: 0,
 
     display: function(ingredient){
         document.getElementById("editIngBtn").onclick = ()=>{controller.openSidebar("editIngredient", ingredient)};
+        document.getElementById("removeIngBtn").onclick = ()=>{this.remove(ingredient)};
         document.getElementById("ingredientDetailsCategory").innerText = ingredient.ingredient.category;
         document.getElementById("ingredientDetailsName").innerText = ingredient.ingredient.name;
         document.getElementById("ingredientStock").innerText = ingredient.getQuantityDisplay();
@@ -2412,10 +2412,10 @@ let ingredientDetails = {
         }
     },
 
-    remove: function(ingredientsStrand){
+    remove: function(ingredient){
         for(let i = 0; i < merchant.recipes.length; i++){
             for(let j = 0; j < merchant.recipes[i].ingredients.length; j++){
-                if(this.ingredient.ingredient === merchant.recipes[i].ingredients[j].ingredient){
+                if(ingredient.ingredient === merchant.recipes[i].ingredients[j].ingredient){
                     banner.createError("MUST REMOVE INGREDIENT FROM ALL RECIPES BEFORE REMOVING FROM INVENTORY");
                     return;
                 }
@@ -2425,16 +2425,17 @@ let ingredientDetails = {
         let loader = document.getElementById("loaderContainer");
         loader.style.display = "flex";
 
-        fetch(`/ingredients/remove/${this.ingredient.ingredient.id}`, {
-            method: "DELETE",
+        fetch(`/ingredients/remove/${ingredient.ingredient.id}`, {
+            method: "delete",
         })
             .then((response) => response.json())
             .then((response)=>{
                 if(typeof(response) === "string"){
                     banner.createError(response);
                 }else{
-                    merchant.removeIngredient(this.ingredient);
-                    ingredientsStrand.display();
+                    merchant.removeIngredient(ingredient);
+                    
+                    controller.openStrand("ingredients");
                     banner.createNotification("INGREDIENT REMOVED");
                 }
             })

+ 8 - 7
views/dashboardPage/js/ingredientDetails.js

@@ -1,9 +1,9 @@
 let ingredientDetails = {
-    ingredient: {},
     dailyUse: 0,
 
     display: function(ingredient){
         document.getElementById("editIngBtn").onclick = ()=>{controller.openSidebar("editIngredient", ingredient)};
+        document.getElementById("removeIngBtn").onclick = ()=>{this.remove(ingredient)};
         document.getElementById("ingredientDetailsCategory").innerText = ingredient.ingredient.category;
         document.getElementById("ingredientDetailsName").innerText = ingredient.ingredient.name;
         document.getElementById("ingredientStock").innerText = ingredient.getQuantityDisplay();
@@ -49,10 +49,10 @@ let ingredientDetails = {
         }
     },
 
-    remove: function(ingredientsStrand){
+    remove: function(ingredient){
         for(let i = 0; i < merchant.recipes.length; i++){
             for(let j = 0; j < merchant.recipes[i].ingredients.length; j++){
-                if(this.ingredient.ingredient === merchant.recipes[i].ingredients[j].ingredient){
+                if(ingredient.ingredient === merchant.recipes[i].ingredients[j].ingredient){
                     banner.createError("MUST REMOVE INGREDIENT FROM ALL RECIPES BEFORE REMOVING FROM INVENTORY");
                     return;
                 }
@@ -62,16 +62,17 @@ let ingredientDetails = {
         let loader = document.getElementById("loaderContainer");
         loader.style.display = "flex";
 
-        fetch(`/ingredients/remove/${this.ingredient.ingredient.id}`, {
-            method: "DELETE",
+        fetch(`/ingredients/remove/${ingredient.ingredient.id}`, {
+            method: "delete",
         })
             .then((response) => response.json())
             .then((response)=>{
                 if(typeof(response) === "string"){
                     banner.createError(response);
                 }else{
-                    merchant.removeIngredient(this.ingredient);
-                    ingredientsStrand.display();
+                    merchant.removeIngredient(ingredient);
+                    
+                    controller.openStrand("ingredients");
                     banner.createNotification("INGREDIENT REMOVED");
                 }
             })