diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-15 11:53:26 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-08-19 17:26:35 +0200 |
commit | 453e83ea5d81d203ba34bc43cd5c2c750ba40568 (patch) | |
tree | 604e02f4343d13a4ba42e1fb7527ba6ab9111712 /server/helpers/custom-validators | |
parent | 13176a07a95984a53cc59aec5217f2ce9806d1bc (diff) | |
download | PeerTube-453e83ea5d81d203ba34bc43cd5c2c750ba40568.tar.gz PeerTube-453e83ea5d81d203ba34bc43cd5c2c750ba40568.tar.zst PeerTube-453e83ea5d81d203ba34bc43cd5c2c750ba40568.zip |
Stronger model typings
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r-- | server/helpers/custom-validators/video-ownership.ts | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/server/helpers/custom-validators/video-ownership.ts b/server/helpers/custom-validators/video-ownership.ts index a7771e07b..9570b2799 100644 --- a/server/helpers/custom-validators/video-ownership.ts +++ b/server/helpers/custom-validators/video-ownership.ts | |||
@@ -1,10 +1,10 @@ | |||
1 | import { Response } from 'express' | 1 | import { Response } from 'express' |
2 | import * as validator from 'validator' | ||
3 | import { VideoChangeOwnershipModel } from '../../models/video/video-change-ownership' | 2 | import { VideoChangeOwnershipModel } from '../../models/video/video-change-ownership' |
4 | import { UserModel } from '../../models/account/user' | 3 | import { MVideoChangeOwnershipFull } from '@server/typings/models/video/video-change-ownership' |
4 | import { MUserId } from '@server/typings/models' | ||
5 | 5 | ||
6 | export async function doesChangeVideoOwnershipExist (id: string, res: Response): Promise<boolean> { | 6 | export async function doesChangeVideoOwnershipExist (id: number, res: Response) { |
7 | const videoChangeOwnership = await loadVideoChangeOwnership(id) | 7 | const videoChangeOwnership = await VideoChangeOwnershipModel.load(id) |
8 | 8 | ||
9 | if (!videoChangeOwnership) { | 9 | if (!videoChangeOwnership) { |
10 | res.status(404) | 10 | res.status(404) |
@@ -18,19 +18,7 @@ export async function doesChangeVideoOwnershipExist (id: string, res: Response): | |||
18 | return true | 18 | return true |
19 | } | 19 | } |
20 | 20 | ||
21 | async function loadVideoChangeOwnership (id: string): Promise<VideoChangeOwnershipModel | undefined> { | 21 | export function checkUserCanTerminateOwnershipChange (user: MUserId, videoChangeOwnership: MVideoChangeOwnershipFull, res: Response) { |
22 | if (validator.isInt(id)) { | ||
23 | return VideoChangeOwnershipModel.load(parseInt(id, 10)) | ||
24 | } | ||
25 | |||
26 | return undefined | ||
27 | } | ||
28 | |||
29 | export function checkUserCanTerminateOwnershipChange ( | ||
30 | user: UserModel, | ||
31 | videoChangeOwnership: VideoChangeOwnershipModel, | ||
32 | res: Response | ||
33 | ): boolean { | ||
34 | if (videoChangeOwnership.NextOwner.userId === user.id) { | 22 | if (videoChangeOwnership.NextOwner.userId === user.id) { |
35 | return true | 23 | return true |
36 | } | 24 | } |