]>
Commit | Line | Data |
---|---|---|
1 | import 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, doesAccountNameWithHostExist, doesLocalAccountNameExist } from './shared' | |
6 | ||
7 | const localAccountValidator = [ | |
8 | param('name') | |
9 | .custom(isAccountNameValid), | |
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') | |
23 | .exists(), | |
24 | ||
25 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
26 | logger.debug('Checking accountsNameWithHostGetValidator parameters', { parameters: req.params }) | |
27 | ||
28 | if (areValidationErrors(req, res)) return | |
29 | if (!await doesAccountNameWithHostExist(req.params.accountName, res)) return | |
30 | ||
31 | return next() | |
32 | } | |
33 | ] | |
34 | ||
35 | // --------------------------------------------------------------------------- | |
36 | ||
37 | export { | |
38 | localAccountValidator, | |
39 | accountNameWithHostGetValidator | |
40 | } |