]>
Commit | Line | Data |
---|---|---|
e4f97bab | 1 | import * as express from 'express' |
c8861d5d | 2 | import { param } from 'express-validator' |
3e753302 | 3 | import { isAccountNameValid } from '../../helpers/custom-validators/accounts' |
da854ddd | 4 | import { logger } from '../../helpers/logger' |
a2431b7d | 5 | import { areValidationErrors } from './utils' |
3e753302 | 6 | import { doesAccountNameWithHostExist, doesLocalAccountNameExist } from '../../helpers/middlewares' |
e4f97bab C |
7 | |
8 | const localAccountValidator = [ | |
350e31d6 | 9 | param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'), |
e4f97bab | 10 | |
a2431b7d | 11 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
e4f97bab C |
12 | logger.debug('Checking localAccountValidator parameters', { parameters: req.params }) |
13 | ||
a2431b7d | 14 | if (areValidationErrors(req, res)) return |
0f6acda1 | 15 | if (!await doesLocalAccountNameExist(req.params.name, res)) return |
a2431b7d C |
16 | |
17 | return next() | |
e4f97bab C |
18 | } |
19 | ] | |
20 | ||
418d092a | 21 | const accountNameWithHostGetValidator = [ |
ad9e39fb | 22 | param('accountName').exists().withMessage('Should have an account name with host'), |
e8cb4409 C |
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 | |
0f6acda1 | 28 | if (!await doesAccountNameWithHostExist(req.params.accountName, res)) return |
e8cb4409 C |
29 | |
30 | return next() | |
31 | } | |
32 | ] | |
33 | ||
e4f97bab C |
34 | // --------------------------------------------------------------------------- |
35 | ||
36 | export { | |
265ba139 | 37 | localAccountValidator, |
418d092a | 38 | accountNameWithHostGetValidator |
e4f97bab | 39 | } |