diff options
Diffstat (limited to 'server/server/middlewares/validators/account.ts')
-rw-r--r-- | server/server/middlewares/validators/account.ts | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/server/server/middlewares/validators/account.ts b/server/server/middlewares/validators/account.ts new file mode 100644 index 000000000..a8793752e --- /dev/null +++ b/server/server/middlewares/validators/account.ts | |||
@@ -0,0 +1,35 @@ | |||
1 | import express from 'express' | ||
2 | import { param } from 'express-validator' | ||
3 | import { isAccountNameValid } from '../../helpers/custom-validators/accounts.js' | ||
4 | import { areValidationErrors, doesAccountNameWithHostExist, doesLocalAccountNameExist } from './shared/index.js' | ||
5 | |||
6 | const localAccountValidator = [ | ||
7 | param('name') | ||
8 | .custom(isAccountNameValid), | ||
9 | |||
10 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
11 | if (areValidationErrors(req, res)) return | ||
12 | if (!await doesLocalAccountNameExist(req.params.name, res)) return | ||
13 | |||
14 | return next() | ||
15 | } | ||
16 | ] | ||
17 | |||
18 | const accountNameWithHostGetValidator = [ | ||
19 | param('accountName') | ||
20 | .exists(), | ||
21 | |||
22 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
23 | if (areValidationErrors(req, res)) return | ||
24 | if (!await doesAccountNameWithHostExist(req.params.accountName, res)) return | ||
25 | |||
26 | return next() | ||
27 | } | ||
28 | ] | ||
29 | |||
30 | // --------------------------------------------------------------------------- | ||
31 | |||
32 | export { | ||
33 | localAccountValidator, | ||
34 | accountNameWithHostGetValidator | ||
35 | } | ||