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