You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
main
${ noResults }
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.js'
|
|||
import { areValidationErrors, doesAccountNameWithHostExist, doesLocalAccountNameExist } from './shared/index.js'
|
|||
|
|||
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
|
|||
}
|