diff options
Diffstat (limited to 'server/middlewares/validators/account.ts')
-rw-r--r-- | server/middlewares/validators/account.ts | 26 |
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { param } from 'express-validator/check' | 2 | import { param } from 'express-validator/check' |
3 | import { logger } from '../../helpers' | 3 | import { logger } from '../../helpers' |
4 | import { isAccountNameValid } from '../../helpers/custom-validators/accounts' | 4 | import { checkLocalAccountNameExists, isAccountNameValid } from '../../helpers/custom-validators/accounts' |
5 | import { database as db } from '../../initializers/database' | ||
6 | import { AccountInstance } from '../../models' | ||
7 | import { checkErrors } from './utils' | 5 | import { checkErrors } from './utils' |
8 | 6 | ||
9 | const localAccountValidator = [ | 7 | const 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 = [ | |||
23 | export { | 21 | export { |
24 | localAccountValidator | 22 | localAccountValidator |
25 | } | 23 | } |
26 | |||
27 | // --------------------------------------------------------------------------- | ||
28 | |||
29 | function 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 | } | ||