From 453e83ea5d81d203ba34bc43cd5c2c750ba40568 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Aug 2019 11:53:26 +0200 Subject: Stronger model typings --- server/helpers/middlewares/video-abuses.ts | 44 +++++++++--------------------- 1 file changed, 13 insertions(+), 31 deletions(-) (limited to 'server/helpers/middlewares/video-abuses.ts') diff --git a/server/helpers/middlewares/video-abuses.ts b/server/helpers/middlewares/video-abuses.ts index b23f1f021..1b573ca37 100644 --- a/server/helpers/middlewares/video-abuses.ts +++ b/server/helpers/middlewares/video-abuses.ts @@ -1,41 +1,23 @@ -import * as express from 'express' -import { VideoChannelModel } from '../../models/video/video-channel' +import { Response } from 'express' +import { VideoAbuseModel } from '../../models/video/video-abuse' -async function doesLocalVideoChannelNameExist (name: string, res: express.Response) { - const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name) +async function doesVideoAbuseExist (abuseId: number, videoId: number, res: Response) { + const videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, videoId) - return processVideoChannelExist(videoChannel, res) -} - -async function doesVideoChannelIdExist (id: number, res: express.Response) { - const videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id) - - return processVideoChannelExist(videoChannel, res) -} - -async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) { - const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain) - - return processVideoChannelExist(videoChannel, res) -} - -// --------------------------------------------------------------------------- - -export { - doesLocalVideoChannelNameExist, - doesVideoChannelIdExist, - doesVideoChannelNameWithHostExist -} - -function processVideoChannelExist (videoChannel: VideoChannelModel, res: express.Response) { - if (!videoChannel) { + if (videoAbuse === null) { res.status(404) - .json({ error: 'Video channel not found' }) + .json({ error: 'Video abuse not found' }) .end() return false } - res.locals.videoChannel = videoChannel + res.locals.videoAbuse = videoAbuse return true } + +// --------------------------------------------------------------------------- + +export { + doesVideoAbuseExist +} -- cgit v1.2.3