浏览代码

Fix small validation bugs

Lee Morgan 6 年之前
父节点
当前提交
06d65290c6

+ 7 - 3
controllers/merchantData.js

@@ -170,10 +170,14 @@ module.exports = {
             return res.redirect("/");
         }
 
-        let validation = Validate.quantity(req.body.quantity);
-        if(validation !== true){
-            return res.json(validation);
+        let validation;
+        for(let i = 0; i < req.body.length; i++){
+            validation = Validator.quantity(req.body[i].quantity);
+            if(validation !== true){
+                return res.json(validation);
+            }
         }
+        
 
         Merchant.findOne({_id: req.session.user})
             .then((merchant)=>{

+ 1 - 0
controllers/orderData.js

@@ -1,6 +1,7 @@
 const Order = require("../models/order.js");
 const Merchant = require("../models/merchant.js");
 const ObjectId = require("mongoose").Types.ObjectId;
+const Validator = require("./validator.js");
 
 module.exports = {
     /*

+ 3 - 2
controllers/recipeData.js

@@ -1,5 +1,6 @@
 const Recipe = require("../models/recipe");
 const Merchant = require("../models/merchant");
+const Validator = require("./validator.js");
 
 module.exports = {
     /*
@@ -20,7 +21,7 @@ module.exports = {
             return res.redirect("/");
         }
 
-        let validation = Validator(req.body);
+        let validation = Validator.recipe(req.body);
         if(validation !== true){
             return res.json(validation);
         }
@@ -72,7 +73,7 @@ module.exports = {
             return res.redirect("/");
         }
 
-        let validation = Validator(req.body);
+        let validation = Validator.recipe(req.body);
         if(validation !== true){
             return res.json(validation);
         }

+ 1 - 0
controllers/validator.js

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

+ 2 - 0
views/dashboardPage/components/components.js

@@ -611,11 +611,13 @@ let addIngredientsComp = {
             },
             body: JSON.stringify(fetchable)
         })
+            .then((response) => response.json())
             .then((response)=>{
                 if(typeof(response) === "string"){
                     banner.createError(response);
                 }else{
                     merchant.editIngredients(newIngredients);
+                    this.isPopulated = false;
                     banner.createNotification("All ingredients added successfully");
                 }
             })