Ver Fonte

Update orderData.js to use mongoose validation.

Lee Morgan há 5 anos atrás
pai
commit
000f6c813d
1 ficheiros alterados com 24 adições e 0 exclusões
  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");
             });
     }