Explorar el Código

Fix bug in inventory check

Lee Morgan hace 6 años
padre
commit
d9993084a0
Se han modificado 3 ficheros con 9 adiciones y 6 borrados
  1. 5 3
      controllers/merchantData.js
  2. 0 1
      controllers/validator.js
  3. 4 2
      views/dashboardPage/home.js

+ 5 - 3
controllers/merchantData.js

@@ -249,9 +249,11 @@ module.exports = {
             return res.redirect("/");
         }
 
-        let validation = Validator.quantity(req.body.quantity);
-        if(validation !== true){
-            return res.json(validation);
+        for(let i = 0; i < req.body.length; i++){
+            let validation = Validator.quantity(req.body[i].quantity);
+            if(validation !== true){
+                return res.json(validation);
+            }
         }
 
         let adjustments = [];

+ 0 - 1
controllers/validator.js

@@ -37,7 +37,6 @@ module.exports = {
     },
 
     quantity: function(num){
-        console.log(num);
         if(isNaN(num) || num === ""){
             return "Quantity must be a number";
         }

+ 4 - 2
views/dashboardPage/home.js

@@ -170,6 +170,8 @@ window.homeStrandObj = {
 
         let loader = document.getElementById("loaderContainer");
         loader.style.display = "flex";
+
+        console.log(changes);
         
         if(changes.length > 0){
             fetch("/merchant/ingredients/update", {
@@ -181,8 +183,8 @@ window.homeStrandObj = {
             })
                 .then((response) => response.json())
                 .then((response)=>{
-                    if(typeof(response.data) === "string"){
-                        banner.createError(response.data);
+                    if(typeof(response) === "string"){
+                        banner.createError(response);
                     }else{
                         merchant.editIngredients(changes);
                         banner.createNotification("Ingredients updated");