From 680c808b9f7e02633f5a39df43879c18194bbd1b Mon Sep 17 00:00:00 2001 From: Danh Nguyen Date: Mon, 17 Feb 2020 19:40:45 -0800 Subject: [PATCH] Update profile.js Prevent user from submitting invalid date ranges for education and experience (currently you can submit a FROM date that is after the TO date which is chronologically invalid). --- routes/api/profile.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/routes/api/profile.js b/routes/api/profile.js index 0980783a..aee93b8b 100644 --- a/routes/api/profile.js +++ b/routes/api/profile.js @@ -171,9 +171,10 @@ router.put( check('company', 'Company is required') .not() .isEmpty(), - check('from', 'From date is required') + check('from', 'From date is required and needs to be from the past') .not() .isEmpty() + .custom((value, { req }) => req.body.to ? value < req.body.to : true) ] ], async (req, res) => { @@ -254,9 +255,10 @@ router.put( check('fieldofstudy', 'Field of study is required') .not() .isEmpty(), - check('from', 'From date is required') + check('from', 'From date is required and needs to be from the past') .not() .isEmpty() + .custom((value, { req }) => req.body.to ? value < req.body.to : true) ] ], async (req, res) => {