1 | const { check } = require('q3-core-composer');
|
2 | const { exception } = require('q3-core-responder');
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | const checkMsg = (v, { req, path }) => req.t.val(path, [v]);
|
8 |
|
9 | const checkEmail = check('email')
|
10 | .isEmail()
|
11 | .withMessage((v, { req }) =>
|
12 | req.t('validations:isEmail'),
|
13 | );
|
14 |
|
15 | const checkNewPassword = check('newPassword')
|
16 | .isString()
|
17 | .custom((value, { req }) => {
|
18 | if (value !== req.body.confirmNewPassword)
|
19 | exception('Validation')
|
20 | .field('confirmNewPassword')
|
21 | .throw();
|
22 |
|
23 | return value;
|
24 | })
|
25 | .withMessage((v, { req }) =>
|
26 | req.t('validations:newPassword'),
|
27 | );
|
28 |
|
29 | const reportMongoId = (v, { req }) =>
|
30 | req.t('validations:mongo', [v]);
|
31 |
|
32 | module.exports = {
|
33 | checkNewPassword,
|
34 | checkMsg,
|
35 | checkEmail,
|
36 | check,
|
37 | reportMongoId,
|
38 | };
|