From 06a05d5f4784a7cbb27aa1188385b5679845dad8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 16 Aug 2018 15:25:20 +0200 Subject: Add subscriptions endpoints to REST API --- server/helpers/custom-validators/video-channels.ts | 32 +++++++++++++++------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'server/helpers/custom-validators/video-channels.ts') diff --git a/server/helpers/custom-validators/video-channels.ts b/server/helpers/custom-validators/video-channels.ts index 2a6f56840..32faf36f7 100644 --- a/server/helpers/custom-validators/video-channels.ts +++ b/server/helpers/custom-validators/video-channels.ts @@ -5,6 +5,7 @@ import * as validator from 'validator' import { CONSTRAINTS_FIELDS } from '../../initializers' import { VideoChannelModel } from '../../models/video/video-channel' import { exists } from './misc' +import { Response } from 'express' const VIDEO_CHANNELS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_CHANNELS @@ -20,6 +21,12 @@ function isVideoChannelSupportValid (value: string) { return value === null || (exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.SUPPORT)) } +async function isLocalVideoChannelNameExist (name: string, res: Response) { + const videoChannel = await VideoChannelModel.loadLocalByName(name) + + return processVideoChannelExist(videoChannel, res) +} + async function isVideoChannelExist (id: string, res: express.Response) { let videoChannel: VideoChannelModel if (validator.isInt(id)) { @@ -28,23 +35,28 @@ async function isVideoChannelExist (id: string, res: express.Response) { videoChannel = await VideoChannelModel.loadByUUIDAndPopulateAccount(id) } - if (!videoChannel) { - res.status(404) - .json({ error: 'Video channel not found' }) - .end() - - return false - } - - res.locals.videoChannel = videoChannel - return true + return processVideoChannelExist(videoChannel, res) } // --------------------------------------------------------------------------- export { + isLocalVideoChannelNameExist, isVideoChannelDescriptionValid, isVideoChannelNameValid, isVideoChannelSupportValid, isVideoChannelExist } + +function processVideoChannelExist (videoChannel: VideoChannelModel, res: express.Response) { + if (!videoChannel) { + res.status(404) + .json({ error: 'Video channel not found' }) + .end() + + return false + } + + res.locals.videoChannel = videoChannel + return true +} -- cgit v1.2.3