1 import * as express from 'express'
2 import { param } from 'express-validator'
3 import { isAccountNameValid } from '../../helpers/custom-validators/accounts'
4 import { logger } from '../../helpers/logger'
5 import { areValidationErrors } from './utils'
6 import { doesAccountNameWithHostExist, doesLocalAccountNameExist } from '../../helpers/middlewares'
8 const localAccountValidator = [
9 param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'),
11 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
12 logger.debug('Checking localAccountValidator parameters', { parameters: req.params })
14 if (areValidationErrors(req, res)) return
15 if (!await doesLocalAccountNameExist(req.params.name, res)) return
21 const accountNameWithHostGetValidator = [
22 param('accountName').exists().withMessage('Should have an account name with host'),
24 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
25 logger.debug('Checking accountsNameWithHostGetValidator parameters', { parameters: req.params })
27 if (areValidationErrors(req, res)) return
28 if (!await doesAccountNameWithHostExist(req.params.accountName, res)) return
34 // ---------------------------------------------------------------------------
37 localAccountValidator,
38 accountNameWithHostGetValidator