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