]>
Commit | Line | Data |
---|---|---|
1 | import * as express from 'express' | |
2 | import { param } from 'express-validator/check' | |
3 | import { isAccountNameValid, doesAccountNameWithHostExist, doesLocalAccountNameExist } from '../../helpers/custom-validators/accounts' | |
4 | import { logger } from '../../helpers/logger' | |
5 | import { areValidationErrors } from './utils' | |
6 | ||
7 | const localAccountValidator = [ | |
8 | param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'), | |
9 | ||
10 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
11 | logger.debug('Checking localAccountValidator parameters', { parameters: req.params }) | |
12 | ||
13 | if (areValidationErrors(req, res)) return | |
14 | if (!await doesLocalAccountNameExist(req.params.name, res)) return | |
15 | ||
16 | return next() | |
17 | } | |
18 | ] | |
19 | ||
20 | const accountNameWithHostGetValidator = [ | |
21 | param('accountName').exists().withMessage('Should have an account name with host'), | |
22 | ||
23 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
24 | logger.debug('Checking accountsNameWithHostGetValidator parameters', { parameters: req.params }) | |
25 | ||
26 | if (areValidationErrors(req, res)) return | |
27 | if (!await doesAccountNameWithHostExist(req.params.accountName, res)) return | |
28 | ||
29 | return next() | |
30 | } | |
31 | ] | |
32 | ||
33 | // --------------------------------------------------------------------------- | |
34 | ||
35 | export { | |
36 | localAccountValidator, | |
37 | accountNameWithHostGetValidator | |
38 | } |