check('urlGitHub') .optional() .custom((v) => (v === '' ? true : validator.isURL(v))) .withMessage('NOT_A_VALID_URL')
body("isbn", "ISBN must not be empty").isLength({ min: 1 }).trim().custom((value,{req}) => { return Book.findOne({isbn : value,user: req.user._id}).then(book => { if (book) { return Promise.reject("Book already exist with this ISBN no."); } }); })
router.post('/reset/:token', [ check('password').not().isEmpty().isLength({min: 6}).withMessage('Must be at least 6 chars long'), check('confirmPassword', 'Passwords do not match').custom((value, {req}) => (value === req.body.password)), ], validate, Password.resetPassword);
body("vehicle", "If you have a vehicle please provide a its manufacture year") .custom(a => { if (a && "year" in a) { const currentYear = new Date().getFullYear(); // comparing year with age of the oldest and the most recent vehicule if (a.year === parseInt(a.year, 10) && (a.year >= 1885) && (a.year <= (currentYear + 1))) { return true; } else return false; } else return true; })
body('confirm') .custom((value, {req}) => { if (value !== req.body.password) { throw new Error('Password must be symbols') } return true }) .trim()
body("email").isLength({ min: 1 }).trim().withMessage("Email must be specified.") .isEmail().withMessage("Email must be a valid email address.").custom((value) => { return UserModel.findOne({email : value}).then((user) => { if (user) { return Promise.reject("E-mail already in use"); } }); })
body("risk_questions", "The Risk answers must be an array with 3 booleans (only 0 and 1 are allowed))").isArray({min: 3, max: 3}) .custom(a => { return a.every((e) => { if (0 >= Number(e) || Number(e) <= 1) { return true ; } else return false; }); })
body('email') .isEmail() .withMessage('Enter valid email') .custom(async (value, req) => { try { const user = await User.findOne({email: value}) if (user) { return Promise.reject('User is also exist') } } catch (e) { console.log(e); } }) .normalizeEmail()
body("house", "The attribute ownership status should can be \"owned\" or \"mortgaged\"") .custom(a => { if (a && "ownership_status" in a) { if (a.ownership_status === "owned" || a.ownership_status === "mortgaged") { return true; } else return false; } else return true; })
body("isbn", "ISBN must not be empty").isLength({ min: 1 }).trim().custom((value,{req}) => { return Book.findOne({isbn : value,user: req.user._id, _id: { "$ne": req.params.id }}).then(book => { if (book) { return Promise.reject("Book already exist with this ISBN no."); } }); })
check('urlGitHub') .optional() .custom((v) => (v === '' ? true : validator.isURL(v))) .withMessage('NOT_A_VALID_URL')
check('urlGitHub') .optional() .custom((v) => (v === '' ? true : validator.isURL(v))) .withMessage('NOT_A_VALID_URL')
check('urlTwitter') .optional() .custom((v) => (v === '' ? true : validator.isURL(v))) .withMessage('NOT_A_VALID_URL')
check('urlTwitter') .optional() .custom((v) => (v === '' ? true : validator.isURL(v))) .withMessage('NOT_A_VALID_URL')
check('urlTwitter') .optional() .custom((v) => (v === '' ? true : validator.isURL(v))) .withMessage('NOT_A_VALID_URL')