diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-12 17:53:50 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-13 16:50:33 +0100 |
commit | 3fd3ab2d34d512b160a5e6084d7609be7b4f4452 (patch) | |
tree | e5ca358287fca6ecacce83defcf23af1e8e9f419 /server/middlewares/validators/video-channels.ts | |
parent | c893d4514e6ecbf282c7985fe5f82b8acd8a1137 (diff) | |
download | PeerTube-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.ts | 19 |
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param } from 'express-validator/check' | 2 | import { body, param } from 'express-validator/check' |
3 | import { UserRight } from '../../../shared' | 3 | import { UserRight } from '../../../shared' |
4 | import { isIdValid } from '../../helpers/custom-validators/misc' | 4 | import { logger } from '../../helpers' |
5 | import { isAccountIdExist } from '../../helpers/custom-validators/accounts' | ||
6 | import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' | ||
5 | import { | 7 | import { |
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' |
10 | import { isIdOrUUIDValid } from '../../helpers/index' | 12 | import { UserModel } from '../../models/account/user' |
11 | import { logger } from '../../helpers/logger' | 13 | import { VideoChannelModel } from '../../models/video/video-channel' |
12 | import { database as db } from '../../initializers' | 14 | import { VideoChannelShareModel } from '../../models/video/video-channel-share' |
13 | import { UserInstance } from '../../models' | ||
14 | import { areValidationErrors } from './utils' | 15 | import { areValidationErrors } from './utils' |
15 | import { isAccountIdExist } from '../../helpers/custom-validators/accounts' | ||
16 | import { VideoChannelInstance } from '../../models/video/video-channel-interface' | ||
17 | 16 | ||
18 | const listVideoAccountChannelsValidator = [ | 17 | const 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 | ||
137 | function checkUserCanDeleteVideoChannel (user: UserInstance, videoChannel: VideoChannelInstance, res: express.Response) { | 136 | function 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 | ||
161 | async function checkVideoChannelIsNotTheLastOne (res: express.Response) { | 160 | async 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) |