aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/account.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators/account.ts')
-rw-r--r--server/middlewares/validators/account.ts26
1 files changed, 2 insertions, 24 deletions
diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts
index 07ae76b63..47ed6a7bb 100644
--- a/server/middlewares/validators/account.ts
+++ b/server/middlewares/validators/account.ts
@@ -1,9 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import { param } from 'express-validator/check' 2import { param } from 'express-validator/check'
3import { logger } from '../../helpers' 3import { logger } from '../../helpers'
4import { isAccountNameValid } from '../../helpers/custom-validators/accounts' 4import { checkLocalAccountNameExists, isAccountNameValid } from '../../helpers/custom-validators/accounts'
5import { database as db } from '../../initializers/database'
6import { AccountInstance } from '../../models'
7import { checkErrors } from './utils' 5import { checkErrors } from './utils'
8 6
9const localAccountValidator = [ 7const localAccountValidator = [
@@ -13,7 +11,7 @@ const localAccountValidator = [
13 logger.debug('Checking localAccountValidator parameters', { parameters: req.params }) 11 logger.debug('Checking localAccountValidator parameters', { parameters: req.params })
14 12
15 checkErrors(req, res, () => { 13 checkErrors(req, res, () => {
16 checkLocalAccountExists(req.params.name, res, next) 14 checkLocalAccountNameExists(req.params.name, res, next)
17 }) 15 })
18 } 16 }
19] 17]
@@ -23,23 +21,3 @@ const localAccountValidator = [
23export { 21export {
24 localAccountValidator 22 localAccountValidator
25} 23}
26
27// ---------------------------------------------------------------------------
28
29function checkLocalAccountExists (name: string, res: express.Response, callback: (err: Error, account: AccountInstance) => void) {
30 db.Account.loadLocalByName(name)
31 .then(account => {
32 if (!account) {
33 return res.status(404)
34 .send({ error: 'Account not found' })
35 .end()
36 }
37
38 res.locals.account = account
39 return callback(null, account)
40 })
41 .catch(err => {
42 logger.error('Error in account request validator.', err)
43 return res.sendStatus(500)
44 })
45}