-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidator.js
More file actions
33 lines (30 loc) · 923 Bytes
/
Copy pathvalidator.js
File metadata and controls
33 lines (30 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const { body, validationResult } = require('express-validator');
const userValidationRules = () => {
return [
body('name', 'Name is required').not().isEmpty(),
body('email', 'E-mail is invalid').isEmail(),
body('username', 'Username is required').not().isEmpty(),
body('password', 'Password must contain at least 5 characters').isLength({ min: 5 }),
body('password_confirm').custom((value, { req }) => {
if (value !== req.body.password) {
throw new Error('Password confirmation does not match the password');
}
return true;
})
]
}
const dumpValidationRules = () => {
return [
body('title', 'Title is required').not().isEmpty(),
body('body', 'The file is empty').notEmpty()
]
}
const validate = (req, res, next) => {
req.errors = validationResult(req);
next();
}
module.exports = {
userValidationRules,
dumpValidationRules,
validate,
}