diff options
Diffstat (limited to 'server/middlewares/validators/follows.ts')
-rw-r--r-- | server/middlewares/validators/follows.ts | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts index ddc4c1de1..605872ecf 100644 --- a/server/middlewares/validators/follows.ts +++ b/server/middlewares/validators/follows.ts | |||
@@ -4,7 +4,7 @@ import { isTestInstance } from '../../helpers/core-utils' | |||
4 | import { isEachUniqueHostValid } from '../../helpers/custom-validators/servers' | 4 | import { isEachUniqueHostValid } from '../../helpers/custom-validators/servers' |
5 | import { logger } from '../../helpers/logger' | 5 | import { logger } from '../../helpers/logger' |
6 | import { CONFIG, database as db } from '../../initializers' | 6 | import { CONFIG, database as db } from '../../initializers' |
7 | import { checkErrors } from './utils' | 7 | import { areValidationErrors } from './utils' |
8 | import { getServerAccount } from '../../helpers/utils' | 8 | import { getServerAccount } from '../../helpers/utils' |
9 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | 9 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' |
10 | 10 | ||
@@ -23,34 +23,30 @@ const followValidator = [ | |||
23 | 23 | ||
24 | logger.debug('Checking follow parameters', { parameters: req.body }) | 24 | logger.debug('Checking follow parameters', { parameters: req.body }) |
25 | 25 | ||
26 | checkErrors(req, res, next) | 26 | if (areValidationErrors(req, res)) return |
27 | |||
28 | return next() | ||
27 | } | 29 | } |
28 | ] | 30 | ] |
29 | 31 | ||
30 | const removeFollowingValidator = [ | 32 | const removeFollowingValidator = [ |
31 | param('accountId').custom(isIdOrUUIDValid).withMessage('Should have a valid account id'), | 33 | param('accountId').custom(isIdOrUUIDValid).withMessage('Should have a valid account id'), |
32 | 34 | ||
33 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 35 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
34 | logger.debug('Checking unfollow parameters', { parameters: req.params }) | 36 | logger.debug('Checking unfollow parameters', { parameters: req.params }) |
35 | 37 | ||
36 | checkErrors(req, res, async () => { | 38 | if (areValidationErrors(req, res)) return |
37 | try { | ||
38 | const serverAccount = await getServerAccount() | ||
39 | const follow = await db.AccountFollow.loadByAccountAndTarget(serverAccount.id, req.params.accountId) | ||
40 | 39 | ||
41 | if (!follow) { | 40 | const serverAccount = await getServerAccount() |
42 | return res.status(404) | 41 | const follow = await db.AccountFollow.loadByAccountAndTarget(serverAccount.id, req.params.accountId) |
43 | .end() | ||
44 | } | ||
45 | 42 | ||
46 | res.locals.follow = follow | 43 | if (!follow) { |
44 | return res.status(404) | ||
45 | .end() | ||
46 | } | ||
47 | 47 | ||
48 | return next() | 48 | res.locals.follow = follow |
49 | } catch (err) { | 49 | return next() |
50 | logger.error('Error in remove following validator.', err) | ||
51 | return res.sendStatus(500) | ||
52 | } | ||
53 | }) | ||
54 | } | 50 | } |
55 | ] | 51 | ] |
56 | 52 | ||