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