浏览代码

Update transactionData.js to use mongoose validation.

Lee Morgan 5 年之前
父节点
当前提交
ca2121e4f0
共有 1 个文件被更改,包括 12 次插入0 次删除
  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");
             });
     },