// USER DEACTIVATE ACCOUNT app.post('/user/deactivate-account', async (req, res) => { let { id } = req.session, userPassword = await User.getWhat('password', id), { password } = req.body, samePassword = await User.comparePassword(password, userPassword) req.checkBody('password', 'Password is empty!!').notEmpty() let errors = await req.getValidationResult() if (!errors.isEmpty()) { let array = [] errors.array().forEach(e => array.push(e.msg)) res.json({ mssg: array }) } else if (!samePassword) { res.json({ mssg: 'Wrong password!!' }) } else { await User.deactivate(id, req, res) res.json({ mssg: 'Deactivated your account successfully!!', success: true, }) } })
if (!errors.isEmpty()) { let array = [] errors.array().forEach(e => array.push(e.msg)) res.json({ mssg: array }) } else {
if (!errors.isEmpty()) { let array = [] errors.array().forEach(e => array.push(e.msg)) res.json({ mssg: array }) } else {
if (!errors.isEmpty()) { let array = [] errors.array().forEach(e => array.push(e.msg)) res.json({ mssg: array }) } else {
if (!errors.isEmpty()) { let array = [] errors.array().forEach(e => array.push(e.msg)) res.json({ mssg: array }) } else {
if (!errors.isEmpty()) { let array = [] errors.array().forEach(e => array.push(e.msg)) res.json({ mssg: array }) } else {
if (!errors.isEmpty()) { let array = [] errors.array().forEach(e => array.push(e.msg)) res.json({ mssg: array }) } else {
const handleValidationErrors = (req, res, next) => { const errors = validationResult(req); if (!errors.isEmpty()) { return res.status(422).json({ errors: errors.array() }); } next(); }
const validateRequest = (req, res, next) => { // console.log("Request body", req.body); const errors = validationResult(req).array(); if (errors.length) { return res.status(422).send(errors); } const data = matchedData(req); res.locals.data = data; return next(); }
router.put('/products/:productId/', [ check('name').not().isEmpty() ] , (req, res, next) => { const errors = validationResult(req); if (!errors.isEmpty()) { return res.status(400).json({ errors: errors.array() }); } return ProductController.updateProductById(req, res, next); });
const validateRequest = (req, res, next) => { console.log('Req Body', req.body); const errors = validationResult(req).array({ onlyFirstError: true }); if (errors.length) { return res.status(422).send(errors) } const data = matchedData(req); res.locals.data = data; return next(); }
router.post('/login', [ check('email').isEmail(), check('password').not().isEmpty() ] , (req, res) => { const errors = validationResult(req); if (!errors.isEmpty()) { return res.status(400).json({ errors: errors.array() }); } return AuthControlller.login(req, res); });
const handleValidationError = (req, res) => { const errors = validationResult(req); if (!errors.isEmpty()) { const errorArray = errors.array(); return emitValidationResponse(res, errorArray); } return null; }
router.post('/products', [ check('name').not().isEmpty() ] , (req, res, next) => { const errors = validationResult(req); if (!errors.isEmpty()) { return res.status(400).json({ errors: errors.array() }); } return ProductController.createProduct(req, res, next); });
const handleValidationErrors = (req, res, next) => { const errors = validationResult(req); if (!errors.isEmpty()) { return res.status(422).json({ errors: errors.array() }); } next(); }