]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/account.ts
Refactor middleware helpers
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / account.ts
index ebc2fcf2d89099c72e3effb1f36046a7301fc352..67e4bf8cca25f3063d3f7a6e614f77025ca76a30 100644 (file)
@@ -1,9 +1,9 @@
 import * as express from 'express'
 import { param } from 'express-validator/check'
-import { isAccountIdExist, isAccountNameValid, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts'
-import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
+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'),
@@ -12,20 +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'),
+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 accountsGetValidator parameters', { parameters: req.params })
+    logger.debug('Checking accountsNameWithHostGetValidator parameters', { parameters: req.params })
 
     if (areValidationErrors(req, res)) return
-    if (!await isAccountIdExist(req.params.id, res)) return
+    if (!await doesAccountNameWithHostExist(req.params.accountName, res)) return
 
     return next()
   }
@@ -35,5 +35,5 @@ const accountsGetValidator = [
 
 export {
   localAccountValidator,
-  accountsGetValidator
+  accountNameWithHostGetValidator
 }