]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-caption.ts
Fix multiple server tests
[github/Chocobozzz/PeerTube.git] / server / models / video / video-caption.ts
index b4f17b481c8320dcc1e42ec6b801cf609621e47f..76243bf488ffc02b4ba814f9df51f11a6dd6a060 100644 (file)
@@ -1,4 +1,4 @@
-import * as Sequelize from 'sequelize'
+import { OrderItem, Transaction } from 'sequelize'
 import {
   AllowNull,
   BeforeDestroy,
@@ -12,30 +12,31 @@ import {
   Table,
   UpdatedAt
 } from 'sequelize-typescript'
-import { throwIfNotValid } from '../utils'
+import { buildWhereIdOrUUID, throwIfNotValid } from '../utils'
 import { VideoModel } from './video'
 import { isVideoCaptionLanguageValid } from '../../helpers/custom-validators/video-captions'
 import { VideoCaption } from '../../../shared/models/videos/caption/video-caption.model'
-import { CONFIG, STATIC_PATHS, VIDEO_LANGUAGES } from '../../initializers'
+import { STATIC_PATHS, VIDEO_LANGUAGES } from '../../initializers/constants'
 import { join } from 'path'
 import { logger } from '../../helpers/logger'
 import { remove } from 'fs-extra'
+import { CONFIG } from '../../initializers/config'
 
 export enum ScopeNames {
   WITH_VIDEO_UUID_AND_REMOTE = 'WITH_VIDEO_UUID_AND_REMOTE'
 }
 
-@Scopes({
+@Scopes(() => ({
   [ScopeNames.WITH_VIDEO_UUID_AND_REMOTE]: {
     include: [
       {
         attributes: [ 'uuid', 'remote' ],
-        model: () => VideoModel.unscoped(),
+        model: VideoModel.unscoped(),
         required: true
       }
     ]
   }
-})
+}))
 
 @Table({
   tableName: 'videoCaption',
@@ -96,12 +97,9 @@ export class VideoCaptionModel extends Model<VideoCaptionModel> {
     const videoInclude = {
       model: VideoModel.unscoped(),
       attributes: [ 'id', 'remote', 'uuid' ],
-      where: { }
+      where: buildWhereIdOrUUID(videoId)
     }
 
-    if (typeof videoId === 'string') videoInclude.where['uuid'] = videoId
-    else videoInclude.where['id'] = videoId
-
     const query = {
       where: {
         language
@@ -114,19 +112,19 @@ export class VideoCaptionModel extends Model<VideoCaptionModel> {
     return VideoCaptionModel.findOne(query)
   }
 
-  static insertOrReplaceLanguage (videoId: number, language: string, transaction: Sequelize.Transaction) {
+  static insertOrReplaceLanguage (videoId: number, language: string, transaction: Transaction) {
     const values = {
       videoId,
       language
     }
 
-    return VideoCaptionModel.upsert<VideoCaptionModel>(values, { transaction, returning: true })
+    return (VideoCaptionModel.upsert<VideoCaptionModel>(values, { transaction, returning: true }) as any) // FIXME: typings
       .then(([ caption ]) => caption)
   }
 
   static listVideoCaptions (videoId: number) {
     const query = {
-      order: [ [ 'language', 'ASC' ] ],
+      order: [ [ 'language', 'ASC' ] ] as OrderItem[],
       where: {
         videoId
       }
@@ -139,7 +137,7 @@ export class VideoCaptionModel extends Model<VideoCaptionModel> {
     return VIDEO_LANGUAGES[language] || 'Unknown'
   }
 
-  static deleteAllCaptionsOfRemoteVideo (videoId: number, transaction: Sequelize.Transaction) {
+  static deleteAllCaptionsOfRemoteVideo (videoId: number, transaction: Transaction) {
     const query = {
       where: {
         videoId