From 453e83ea5d81d203ba34bc43cd5c2c750ba40568 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Aug 2019 11:53:26 +0200 Subject: Stronger model typings --- .../helpers/custom-validators/video-ownership.ts | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) (limited to 'server/helpers/custom-validators') 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 @@ import { Response } from 'express' -import * as validator from 'validator' import { VideoChangeOwnershipModel } from '../../models/video/video-change-ownership' -import { UserModel } from '../../models/account/user' +import { MVideoChangeOwnershipFull } from '@server/typings/models/video/video-change-ownership' +import { MUserId } from '@server/typings/models' -export async function doesChangeVideoOwnershipExist (id: string, res: Response): Promise { - const videoChangeOwnership = await loadVideoChangeOwnership(id) +export async function doesChangeVideoOwnershipExist (id: number, res: Response) { + const videoChangeOwnership = await VideoChangeOwnershipModel.load(id) if (!videoChangeOwnership) { res.status(404) @@ -18,19 +18,7 @@ export async function doesChangeVideoOwnershipExist (id: string, res: Response): return true } -async function loadVideoChangeOwnership (id: string): Promise { - if (validator.isInt(id)) { - return VideoChangeOwnershipModel.load(parseInt(id, 10)) - } - - return undefined -} - -export function checkUserCanTerminateOwnershipChange ( - user: UserModel, - videoChangeOwnership: VideoChangeOwnershipModel, - res: Response -): boolean { +export function checkUserCanTerminateOwnershipChange (user: MUserId, videoChangeOwnership: MVideoChangeOwnershipFull, res: Response) { if (videoChangeOwnership.NextOwner.userId === user.id) { return true } -- cgit v1.2.3