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