From c1e791bad0b079af67398f6407221e6dcbb573dd Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Wed, 25 Jul 2018 22:01:25 +0200 Subject: expliciting type checks and predicates (server only) --- server/helpers/custom-validators/videos.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'server/helpers/custom-validators/videos.ts') diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index b5cb126d9..70904af0c 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts @@ -150,7 +150,7 @@ function checkUserCanManageVideo (user: UserModel, video: VideoModel, right: Use } async function isVideoExist (id: string, res: Response) { - let video: VideoModel + let video: VideoModel | null if (validator.isInt(id)) { video = await VideoModel.loadAndPopulateAccountAndServerAndTags(+id) @@ -158,7 +158,7 @@ async function isVideoExist (id: string, res: Response) { video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(id) } - if (!video) { + if (video && video !== null) { res.status(404) .json({ error: 'Video not found' }) .end() @@ -173,7 +173,7 @@ async function isVideoExist (id: string, res: Response) { async function isVideoChannelOfAccountExist (channelId: number, user: UserModel, res: Response) { if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) { const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId) - if (!videoChannel) { + if (videoChannel && videoChannel !== null) { res.status(400) .json({ error: 'Unknown video video channel on this instance.' }) .end() @@ -186,7 +186,7 @@ async function isVideoChannelOfAccountExist (channelId: number, user: UserModel, } const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, user.Account.id) - if (!videoChannel) { + if (videoChannel && videoChannel !== null) { res.status(400) .json({ error: 'Unknown video video channel for this account.' }) .end() -- cgit v1.2.3