1 import * as express from 'express'
2 import { param } from 'express-validator/check'
6 isAccountNameWithHostExist,
7 isLocalAccountNameExist
8 } from '../../helpers/custom-validators/accounts'
9 import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
10 import { logger } from '../../helpers/logger'
11 import { areValidationErrors } from './utils'
13 const localAccountValidator = [
14 param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'),
16 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
17 logger.debug('Checking localAccountValidator parameters', { parameters: req.params })
19 if (areValidationErrors(req, res)) return
20 if (!await isLocalAccountNameExist(req.params.name, res)) return
26 const accountsGetValidator = [
27 param('id').custom(isIdOrUUIDValid).withMessage('Should have a valid id'),
29 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
30 logger.debug('Checking accountsGetValidator parameters', { parameters: req.params })
32 if (areValidationErrors(req, res)) return
33 if (!await isAccountIdExist(req.params.id, res)) return
39 const accountsNameWithHostGetValidator = [
40 param('nameWithHost').exists().withMessage('Should have an account name with host'),
42 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
43 logger.debug('Checking accountsNameWithHostGetValidator parameters', { parameters: req.params })
45 if (areValidationErrors(req, res)) return
46 if (!await isAccountNameWithHostExist(req.params.nameWithHost, res)) return
52 // ---------------------------------------------------------------------------
55 localAccountValidator,
57 accountsNameWithHostGetValidator