From 57f6896f67cfc570cf3605dd94b0778101b2d9b9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 7 Jul 2020 10:57:04 +0200 Subject: Implement abuses check params --- server/helpers/middlewares/abuses.ts | 13 +++++++++++-- server/helpers/middlewares/accounts.ts | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'server/helpers/middlewares') diff --git a/server/helpers/middlewares/abuses.ts b/server/helpers/middlewares/abuses.ts index 3906f6760..b102273a2 100644 --- a/server/helpers/middlewares/abuses.ts +++ b/server/helpers/middlewares/abuses.ts @@ -17,7 +17,6 @@ async function doesVideoAbuseExist (abuseIdArg: number | string, videoUUID: stri if (abuse === null) { res.status(404) .json({ error: 'Video abuse not found' }) - .end() return false } @@ -26,8 +25,18 @@ async function doesVideoAbuseExist (abuseIdArg: number | string, videoUUID: stri return true } -async function doesAbuseExist (abuseIdArg: number | string, videoUUID: string, res: Response) { +async function doesAbuseExist (abuseId: number | string, res: Response) { + const abuse = await AbuseModel.loadById(parseInt(abuseId + '', 10)) + if (!abuse) { + res.status(404) + .json({ error: 'Video abuse not found' }) + + return false + } + + res.locals.abuse = abuse + return true } // --------------------------------------------------------------------------- diff --git a/server/helpers/middlewares/accounts.ts b/server/helpers/middlewares/accounts.ts index bddea7eaa..29b4ed1a6 100644 --- a/server/helpers/middlewares/accounts.ts +++ b/server/helpers/middlewares/accounts.ts @@ -3,8 +3,8 @@ import { AccountModel } from '../../models/account/account' import * as Bluebird from 'bluebird' import { MAccountDefault } from '../../types/models' -function doesAccountIdExist (id: number, res: Response, sendNotFound = true) { - const promise = AccountModel.load(id) +function doesAccountIdExist (id: number | string, res: Response, sendNotFound = true) { + const promise = AccountModel.load(parseInt(id + '', 10)) return doesAccountExist(promise, res, sendNotFound) } -- cgit v1.2.3