1 import * as express from 'express'
2 import { param } from 'express-validator/check'
3 import { isAccountIdExist, isAccountNameValid, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts'
4 import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
5 import { logger } from '../../helpers/logger'
6 import { areValidationErrors } from './utils'
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 isLocalAccountNameExist(req.params.name, res)) return
21 const accountsGetValidator = [
22 param('id').custom(isIdOrUUIDValid).withMessage('Should have a valid id'),
24 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
25 logger.debug('Checking accountsGetValidator parameters', { parameters: req.params })
27 if (areValidationErrors(req, res)) return
28 if (!await isAccountIdExist(req.params.id, res)) return
34 // ---------------------------------------------------------------------------
37 localAccountValidator,