2021-08-27 12:32:44 +00:00
|
|
|
import express from 'express'
|
2019-07-25 14:23:44 +00:00
|
|
|
import { param } from 'express-validator'
|
2019-07-23 08:40:39 +00:00
|
|
|
import { isAccountNameValid } from '../../helpers/custom-validators/accounts'
|
2017-12-28 10:16:08 +00:00
|
|
|
import { logger } from '../../helpers/logger'
|
2021-06-03 15:33:44 +00:00
|
|
|
import { areValidationErrors, doesAccountNameWithHostExist, doesLocalAccountNameExist } from './shared'
|
2017-11-09 16:51:58 +00:00
|
|
|
|
|
|
|
const localAccountValidator = [
|
2022-08-17 12:27:04 +00:00
|
|
|
param('name')
|
|
|
|
.custom(isAccountNameValid),
|
2017-11-09 16:51:58 +00:00
|
|
|
|
2017-11-27 16:30:46 +00:00
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
2017-11-09 16:51:58 +00:00
|
|
|
logger.debug('Checking localAccountValidator parameters', { parameters: req.params })
|
|
|
|
|
2017-11-27 16:30:46 +00:00
|
|
|
if (areValidationErrors(req, res)) return
|
2019-03-19 08:26:50 +00:00
|
|
|
if (!await doesLocalAccountNameExist(req.params.name, res)) return
|
2017-11-27 16:30:46 +00:00
|
|
|
|
|
|
|
return next()
|
2017-11-09 16:51:58 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2019-02-26 09:55:40 +00:00
|
|
|
const accountNameWithHostGetValidator = [
|
2022-08-17 12:27:04 +00:00
|
|
|
param('accountName')
|
|
|
|
.exists(),
|
2018-02-21 15:44:18 +00:00
|
|
|
|
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
logger.debug('Checking accountsNameWithHostGetValidator parameters', { parameters: req.params })
|
|
|
|
|
|
|
|
if (areValidationErrors(req, res)) return
|
2019-03-19 08:26:50 +00:00
|
|
|
if (!await doesAccountNameWithHostExist(req.params.accountName, res)) return
|
2018-02-21 15:44:18 +00:00
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2017-11-09 16:51:58 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2018-01-03 15:38:50 +00:00
|
|
|
localAccountValidator,
|
2019-02-26 09:55:40 +00:00
|
|
|
accountNameWithHostGetValidator
|
2017-11-09 16:51:58 +00:00
|
|
|
}
|