check('urlGitHub') .optional() .custom((v) => (v === '' ? true : validator.isURL(v))) .withMessage('NOT_A_VALID_URL')
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("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"); } }); })
function validationRules() { return [ check('first_name').not().isEmpty().withMessage('First name is required'), check('last_name').not().isEmpty().withMessage('Last name is required'), check('gender').not().isEmpty().withMessage('Gender is required').isIn(['M', 'F']), check('date_of_birth').toDate().optional({ checkFalsy: true }), check('mobile').optional({ checkFalsy: true }).isInt(), check('address').optional({ checkFalsy: true, nullable: true }).isLength({ min: 10 }).withMessage('Please enter minimum 10 characters'), check('email').optional({ checkFalsy: true, nullable: true }).isEmail().withMessage('Please enter valid email') ]; }
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()
router.put( "/signup", [ body("email") .isEmail() .withMessage("not valid email") .custom((value, { req }) => { return User.findOne({ email: value }).then(userDocument => { if (userDocument) return Promise.reject("email already exists"); }); }) .normalizeEmail(), trimAndMinLength("password", 5), trimAndNotEmpty("name") ], authController.signup );
router.post('/', [ body('name').exists().withMessage('name is required.'), ], (req, res, next) => { const errors = validationResult(req); if (!errors.isEmpty()) { return res.status(400).json({error: errors.mapped() }); } const data = { chaincodeId: CHAINCODE_NAME, fcn: 'createAccount', args: [req.body.name], }; invoke(data, req, res, next); });
router.post(`/${DEPOSIT}/`, [ body('to_account_no').exists().withMessage('to_account_no is required'), body('to_account_no').isLength({min:16, max:16}).matches(/\d/).withMessage('account_no is not 16 digits'), body('amount').exists().withMessage('amount is required'), body('amount').isInt({min:0}).withMessage('amount is not int or amount is less than zero'), ], (req, res, next) => { const errors = validationResult(req); if (!errors.isEmpty()) { return res.status(400).json({error: errors.mapped() }); } const data = { chaincodeId: CHAINCODE_NAME, fcn: 'deposit', args: [req.body.to_account_no, req.body.amount.toString()], }; invoke(data, req, res, next); });
router.patch('/api/user', [ apiAuthRequired, adminOnly, body('user').exists().withMessage('user is required'), validateRequest, ], async (req, res, next) => { try { const selectQuery = { login: req.body.user }; const updateQuery = { $set: _.pick(req.body, ['authority']) }; const status = await User.updateOne(selectQuery, updateQuery); res.json(status); } catch (err) { next(err); } } );
router.post(`/${WITHDRAW}/`, [ body('from_account_no').exists().withMessage('from_account_no is required'), body('from_account_no').isLength({min:16, max:16}).matches(/\d/).withMessage('account_no is not 16 digits'), body('amount').exists().withMessage('amount is required'), body('amount').isInt({min:0}).withMessage('amount is not int or amount is less than zero'), ], (req, res, next) => { const errors = validationResult(req); if (!errors.isEmpty()) { return res.status(400).json({error: errors.mapped() }); } const data = { chaincodeId: CHAINCODE_NAME, fcn: 'withdraw', args: [req.body.from_account_no, req.body.amount.toString()], }; invoke(data, req, res, next); });
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('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')