Parcourir la source

Update validation for all ingredient routes

Lee Morgan il y a 6 ans
Parent
commit
1e65411099
3 fichiers modifiés avec 7 ajouts et 6 suppressions
  1. 6 4
      controllers/ingredientData.js
  2. 0 1
      controllers/merchantData.js
  3. 1 1
      controllers/recipeData.js

+ 6 - 4
controllers/ingredientData.js

@@ -35,11 +35,13 @@ module.exports = {
             return res.redirect("/");
             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));
         let ingredientPromise = Ingredient.create((req.body.ingredient));

+ 0 - 1
controllers/merchantData.js

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

+ 1 - 1
controllers/recipeData.js

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