36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
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
|
|
}
|