X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Faccount.ts;h=cbdcef2fd480298ab4f966f8c5bf0413138d77d4;hb=e1c5503114deef954731904695cd40dccfcef555;hp=0c4b7051dc51e14bc5fcf5df059976e013792b0c;hpb=e8cb44090e654fda339506dccfcec7fea8722723;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts index 0c4b7051d..cbdcef2fd 100644 --- a/server/middlewares/validators/account.ts +++ b/server/middlewares/validators/account.ts @@ -1,14 +1,9 @@ import * as express from 'express' -import { param } from 'express-validator/check' -import { - isAccountIdExist, - isAccountNameValid, - isAccountNameWithHostExist, - isLocalAccountNameExist -} from '../../helpers/custom-validators/accounts' -import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' +import { param } from 'express-validator' +import { isAccountNameValid } from '../../helpers/custom-validators/accounts' import { logger } from '../../helpers/logger' import { areValidationErrors } from './utils' +import { doesAccountNameWithHostExist, doesLocalAccountNameExist } from '../../helpers/middlewares' const localAccountValidator = [ param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'), @@ -17,33 +12,20 @@ const localAccountValidator = [ logger.debug('Checking localAccountValidator parameters', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await isLocalAccountNameExist(req.params.name, res)) return + if (!await doesLocalAccountNameExist(req.params.name, res)) return return next() } ] -const accountsGetValidator = [ - param('id').custom(isIdOrUUIDValid).withMessage('Should have a valid id'), - - async (req: express.Request, res: express.Response, next: express.NextFunction) => { - logger.debug('Checking accountsGetValidator parameters', { parameters: req.params }) - - if (areValidationErrors(req, res)) return - if (!await isAccountIdExist(req.params.id, res)) return - - return next() - } -] - -const accountsNameWithHostGetValidator = [ - param('nameWithHost').exists().withMessage('Should have an account name with host'), +const accountNameWithHostGetValidator = [ + param('accountName').exists().withMessage('Should have an account name with host'), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking accountsNameWithHostGetValidator parameters', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await isAccountNameWithHostExist(req.params.nameWithHost, res)) return + if (!await doesAccountNameWithHostExist(req.params.accountName, res)) return return next() } @@ -53,6 +35,5 @@ const accountsNameWithHostGetValidator = [ export { localAccountValidator, - accountsGetValidator, - accountsNameWithHostGetValidator + accountNameWithHostGetValidator }