2017-11-09 17:51:58 +01:00
|
|
|
import * as express from 'express'
|
2017-11-13 17:39:41 +01:00
|
|
|
import { param } from 'express-validator/check'
|
2017-11-27 17:30:46 +01:00
|
|
|
import { logger, isLocalAccountNameExist } from '../../helpers'
|
|
|
|
import { isAccountNameValid } from '../../helpers/custom-validators/accounts'
|
|
|
|
import { areValidationErrors } from './utils'
|
2017-11-09 17:51:58 +01:00
|
|
|
|
|
|
|
const localAccountValidator = [
|
2017-11-14 17:31:26 +01:00
|
|
|
param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'),
|
2017-11-09 17:51:58 +01:00
|
|
|
|
2017-11-27 17:30:46 +01:00
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
2017-11-09 17:51:58 +01:00
|
|
|
logger.debug('Checking localAccountValidator parameters', { parameters: req.params })
|
|
|
|
|
2017-11-27 17:30:46 +01:00
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
if (!await isLocalAccountNameExist(req.params.name, res)) return
|
|
|
|
|
|
|
|
return next()
|
2017-11-09 17:51:58 +01:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
localAccountValidator
|
|
|
|
}
|