Просмотр исходного кода

Update orderData.js to use mongoose validation.

Lee Morgan 5 лет назад
Родитель
Сommit
000f6c813d
1 измененных файлов с 24 добавлено и 0 удалено
  1. 24 0
      controllers/orderData.js

+ 24 - 0
controllers/orderData.js

@@ -41,6 +41,12 @@ module.exports = {
                 return res.json(orders);
             })
             .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 RETRIEVE YOUR ORDERS");
             });
     },
@@ -87,6 +93,12 @@ module.exports = {
                 return res.json(orders);
             })
             .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 RETRIEVE YOUR TRANSACTIONS");
             });
     },
@@ -121,6 +133,12 @@ module.exports = {
                 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 SAVE ORDER");
             });
 
@@ -178,6 +196,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 REMOVE ORDER");
             });
     }