Procházet zdrojové kódy

Update validation for all ingredient routes

Lee Morgan před 6 roky
rodič
revize
1e65411099

+ 6 - 4
controllers/ingredientData.js

@@ -35,11 +35,13 @@ module.exports = {
             return res.redirect("/");
         }
 
-        if(!Validator.ingredient(req.body.ingredient)){
-            return res.json("Error:  ingredient contains illegal characters");
+        let validation = Validator.ingredient(req.body.ingredient);
+        if(validation !== true){
+            return res.json(validation);
         }
-        if(!Validator.quantity(req.body.quantity)){
-            return res.json("Error: inappropriate quantity");
+        validation = Validator.quantity(req.body.quantity);
+        if(validation !== true){
+            return res.json(validation);
         }
 
         let ingredientPromise = Ingredient.create((req.body.ingredient));

+ 0 - 1
controllers/merchantData.js

@@ -20,7 +20,6 @@ module.exports = {
     createMerchantNone: async function(req, res){
         let validation =  await Validator.merchant(req.body);
         if(validation !== true){
-            console.log(validation);
             req.session.error = validation;
             return res.redirect("/");
         }

+ 1 - 1
controllers/recipeData.js

@@ -38,7 +38,7 @@ module.exports = {
             })
             .catch((err)=>{
                 return res.json("Error: unable to retrieve user data");
-            })
+            });
 
         recipe.save()
             .then((newRecipe)=>{