aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/video-channels.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-12 17:53:50 +0100
committerChocobozzz <me@florianbigard.com>2017-12-13 16:50:33 +0100
commit3fd3ab2d34d512b160a5e6084d7609be7b4f4452 (patch)
treee5ca358287fca6ecacce83defcf23af1e8e9f419 /server/middlewares/validators/video-channels.ts
parentc893d4514e6ecbf282c7985fe5f82b8acd8a1137 (diff)
downloadPeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.gz
PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.zst
PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.zip
Move models to typescript-sequelize
Diffstat (limited to 'server/middlewares/validators/video-channels.ts')
-rw-r--r--server/middlewares/validators/video-channels.ts19
1 files changed, 9 insertions, 10 deletions
diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts
index 3d31a7e52..660390080 100644
--- a/server/middlewares/validators/video-channels.ts
+++ b/server/middlewares/validators/video-channels.ts
@@ -1,19 +1,18 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param } from 'express-validator/check' 2import { body, param } from 'express-validator/check'
3import { UserRight } from '../../../shared' 3import { UserRight } from '../../../shared'
4import { isIdValid } from '../../helpers/custom-validators/misc' 4import { logger } from '../../helpers'
5import { isAccountIdExist } from '../../helpers/custom-validators/accounts'
6import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc'
5import { 7import {
6 isVideoChannelDescriptionValid, 8 isVideoChannelDescriptionValid,
7 isVideoChannelExist, 9 isVideoChannelExist,
8 isVideoChannelNameValid 10 isVideoChannelNameValid
9} from '../../helpers/custom-validators/video-channels' 11} from '../../helpers/custom-validators/video-channels'
10import { isIdOrUUIDValid } from '../../helpers/index' 12import { UserModel } from '../../models/account/user'
11import { logger } from '../../helpers/logger' 13import { VideoChannelModel } from '../../models/video/video-channel'
12import { database as db } from '../../initializers' 14import { VideoChannelShareModel } from '../../models/video/video-channel-share'
13import { UserInstance } from '../../models'
14import { areValidationErrors } from './utils' 15import { areValidationErrors } from './utils'
15import { isAccountIdExist } from '../../helpers/custom-validators/accounts'
16import { VideoChannelInstance } from '../../models/video/video-channel-interface'
17 16
18const listVideoAccountChannelsValidator = [ 17const listVideoAccountChannelsValidator = [
19 param('accountId').custom(isIdOrUUIDValid).withMessage('Should have a valid account id'), 18 param('accountId').custom(isIdOrUUIDValid).withMessage('Should have a valid account id'),
@@ -109,7 +108,7 @@ const videoChannelsShareValidator = [
109 if (areValidationErrors(req, res)) return 108 if (areValidationErrors(req, res)) return
110 if (!await isVideoChannelExist(req.params.id, res)) return 109 if (!await isVideoChannelExist(req.params.id, res)) return
111 110
112 const share = await db.VideoChannelShare.load(res.locals.video.id, req.params.accountId, undefined) 111 const share = await VideoChannelShareModel.load(res.locals.video.id, req.params.accountId, undefined)
113 if (!share) { 112 if (!share) {
114 return res.status(404) 113 return res.status(404)
115 .end() 114 .end()
@@ -134,7 +133,7 @@ export {
134 133
135// --------------------------------------------------------------------------- 134// ---------------------------------------------------------------------------
136 135
137function checkUserCanDeleteVideoChannel (user: UserInstance, videoChannel: VideoChannelInstance, res: express.Response) { 136function checkUserCanDeleteVideoChannel (user: UserModel, videoChannel: VideoChannelModel, res: express.Response) {
138 // Retrieve the user who did the request 137 // Retrieve the user who did the request
139 if (videoChannel.isOwned() === false) { 138 if (videoChannel.isOwned() === false) {
140 res.status(403) 139 res.status(403)
@@ -159,7 +158,7 @@ function checkUserCanDeleteVideoChannel (user: UserInstance, videoChannel: Video
159} 158}
160 159
161async function checkVideoChannelIsNotTheLastOne (res: express.Response) { 160async function checkVideoChannelIsNotTheLastOne (res: express.Response) {
162 const count = await db.VideoChannel.countByAccount(res.locals.oauth.token.User.Account.id) 161 const count = await VideoChannelModel.countByAccount(res.locals.oauth.token.User.Account.id)
163 162
164 if (count <= 1) { 163 if (count <= 1) {
165 res.status(409) 164 res.status(409)