UNPKG

840 BJavaScriptView Raw
1const { check } = require('q3-core-composer');
2const { exception } = require('q3-core-responder');
3
4/**
5 * Common validations.
6 */
7const checkMsg = (v, { req, path }) => req.t.val(path, [v]);
8
9const checkEmail = check('email')
10 .isEmail()
11 .withMessage((v, { req }) =>
12 req.t('validations:isEmail'),
13 );
14
15const 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
29const reportMongoId = (v, { req }) =>
30 req.t('validations:mongo', [v]);
31
32module.exports = {
33 checkNewPassword,
34 checkMsg,
35 checkEmail,
36 check,
37 reportMongoId,
38};