aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r--server/middlewares/validators/account.ts12
1 files changed, 9 insertions, 3 deletions
diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts
index 0c4b7051d..c01e742da 100644
--- a/server/middlewares/validators/account.ts
+++ b/server/middlewares/validators/account.ts
@@ -2,13 +2,14 @@ import * as express from 'express'
2import { param } from 'express-validator/check' 2import { param } from 'express-validator/check'
3import { 3import {
4 isAccountIdExist, 4 isAccountIdExist,
5 isAccountIdValid,
5 isAccountNameValid, 6 isAccountNameValid,
6 isAccountNameWithHostExist, 7 isAccountNameWithHostExist,
7 isLocalAccountNameExist 8 isLocalAccountNameExist
8} from '../../helpers/custom-validators/accounts' 9} from '../../helpers/custom-validators/accounts'
9import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
10import { logger } from '../../helpers/logger' 10import { logger } from '../../helpers/logger'
11import { areValidationErrors } from './utils' 11import { areValidationErrors } from './utils'
12import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
12 13
13const localAccountValidator = [ 14const localAccountValidator = [
14 param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'), 15 param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'),
@@ -24,13 +25,18 @@ const localAccountValidator = [
24] 25]
25 26
26const accountsGetValidator = [ 27const accountsGetValidator = [
27 param('id').custom(isIdOrUUIDValid).withMessage('Should have a valid id'), 28 param('id').custom(isAccountIdValid).withMessage('Should have a valid id/uuid/name/name with host'),
28 29
29 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 30 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
30 logger.debug('Checking accountsGetValidator parameters', { parameters: req.params }) 31 logger.debug('Checking accountsGetValidator parameters', { parameters: req.params })
31 32
32 if (areValidationErrors(req, res)) return 33 if (areValidationErrors(req, res)) return
33 if (!await isAccountIdExist(req.params.id, res)) return 34
35 let accountFetched = false
36 if (isIdOrUUIDValid(req.params.id)) accountFetched = await isAccountIdExist(req.params.id, res, false)
37 if (!accountFetched) accountFetched = await isAccountNameWithHostExist(req.params.id, res, true)
38
39 if (!accountFetched) return
34 40
35 return next() 41 return next()
36 } 42 }