Browse Source

Update transactionData.js to use mongoose validation.

Lee Morgan 5 years ago
parent
commit
ca2121e4f0
1 changed files with 12 additions and 0 deletions
  1. 12 0
      controllers/transactionData.js

+ 12 - 0
controllers/transactionData.js

@@ -149,6 +149,12 @@ module.exports = {
                 return res.json(response);
             })
             .catch((err)=>{
+                if(typeof(err) === "string"){
+                    return res.json(err);
+                }
+                if(err.name === "ValidationError"){
+                    return res.json(err.errors.name.properties.message);
+                }
                 return res.json("ERROR: UNABLE TO CREATE NEW TRANSACTION");
             });
     },
@@ -192,6 +198,12 @@ module.exports = {
                 return merchant.save();
             })
             .catch((err)=>{
+                if(typeof(err) === "string"){
+                    return res.json(err);
+                }
+                if(err.name === "ValidationError"){
+                    return res.json(err.errors.name.properties.message);
+                }
                 return res.json("ERROR: UNABLE TO DELETE THE TRANSACTION");
             });
     },