blob: 551f67d61fb68dc8d0a506b9cdddfe275dca7ef9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import express from 'express'
import { param } from 'express-validator'
import { isAccountNameValid } from '../../helpers/custom-validators/accounts'
import { areValidationErrors, doesAccountNameWithHostExist, doesLocalAccountNameExist } from './shared'
const localAccountValidator = [
param('name')
.custom(isAccountNameValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
if (areValidationErrors(req, res)) return
if (!await doesLocalAccountNameExist(req.params.name, res)) return
return next()
}
]
const accountNameWithHostGetValidator = [
param('accountName')
.exists(),
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
if (areValidationErrors(req, res)) return
if (!await doesAccountNameWithHostExist(req.params.accountName, res)) return
return next()
}
]
// ---------------------------------------------------------------------------
export {
localAccountValidator,
accountNameWithHostGetValidator
}
|