Improve check jobs parameters tests
[oweals/peertube.git] / server / middlewares / validators / account.ts
1 import * as express from 'express'
2 import { param } from 'express-validator/check'
3 import { isAccountNameValid, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts'
4 import { logger } from '../../helpers/logger'
5 import { areValidationErrors } from './utils'
6
7 const localAccountValidator = [
8   param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'),
9
10   async (req: express.Request, res: express.Response, next: express.NextFunction) => {
11     logger.debug('Checking localAccountValidator parameters', { parameters: req.params })
12
13     if (areValidationErrors(req, res)) return
14     if (!await isLocalAccountNameExist(req.params.name, res)) return
15
16     return next()
17   }
18 ]
19
20 // ---------------------------------------------------------------------------
21
22 export {
23   localAccountValidator
24 }