]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/account.ts
Use saveInTransactionWithRetries helper
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / account.ts
index 70f4e4d3bc5e33a17b4adcc05ead4de5aac526d1..551f67d61fb68dc8d0a506b9cdddfe275dca7ef9 100644 (file)
@@ -1,17 +1,27 @@
-import * as express from 'express'
-import { param } from 'express-validator/check'
-import { logger, isLocalAccountNameExist } from '../../helpers'
+import express from 'express'
+import { param } from 'express-validator'
 import { isAccountNameValid } from '../../helpers/custom-validators/accounts'
-import { areValidationErrors } from './utils'
+import { areValidationErrors, doesAccountNameWithHostExist, doesLocalAccountNameExist } from './shared'
 
 const localAccountValidator = [
-  param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'),
+  param('name')
+    .custom(isAccountNameValid),
 
   async (req: express.Request, res: express.Response, next: express.NextFunction) => {
-    logger.debug('Checking localAccountValidator parameters', { parameters: req.params })
+    if (areValidationErrors(req, res)) return
+    if (!await doesLocalAccountNameExist(req.params.name, res)) return
 
+    return next()
+  }
+]
+
+const accountNameWithHostGetValidator = [
+  param('accountName')
+    .exists(),
+
+  async (req: express.Request, res: express.Response, next: express.NextFunction) => {
     if (areValidationErrors(req, res)) return
-    if (!await isLocalAccountNameExist(req.params.name, res)) return
+    if (!await doesAccountNameWithHostExist(req.params.accountName, res)) return
 
     return next()
   }
@@ -20,5 +30,6 @@ const localAccountValidator = [
 // ---------------------------------------------------------------------------
 
 export {
-  localAccountValidator
+  localAccountValidator,
+  accountNameWithHostGetValidator
 }