]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-change-ownership.ts
Stricter models typing
[github/Chocobozzz/PeerTube.git] / server / models / video / video-change-ownership.ts
index aecb03c14713aed661c8d3456fd08a119da1fadd..7d20a954d6af72880dbe43a6c6860daa16c4ec0b 100644 (file)
@@ -1,10 +1,10 @@
 import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
-import { AccountModel } from '../account/account'
-import { ScopeNames as VideoScopeNames, VideoModel } from './video'
+import { MVideoChangeOwnershipFormattable, MVideoChangeOwnershipFull } from '@server/types/models/video/video-change-ownership'
+import { AttributesOnly } from '@shared/core-utils'
 import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '../../../shared/models/videos'
+import { AccountModel } from '../account/account'
 import { getSort } from '../utils'
-import { MVideoChangeOwnershipFormattable, MVideoChangeOwnershipFull } from '@server/types/models/video/video-change-ownership'
-import * as Bluebird from 'bluebird'
+import { ScopeNames as VideoScopeNames, VideoModel } from './video'
 
 enum ScopeNames {
   WITH_ACCOUNTS = 'WITH_ACCOUNTS',
@@ -46,14 +46,15 @@ enum ScopeNames {
         model: VideoModel.scope([
           VideoScopeNames.WITH_THUMBNAILS,
           VideoScopeNames.WITH_WEBTORRENT_FILES,
-          VideoScopeNames.WITH_STREAMING_PLAYLISTS
+          VideoScopeNames.WITH_STREAMING_PLAYLISTS,
+          VideoScopeNames.WITH_ACCOUNT_DETAILS
         ]),
         required: true
       }
     ]
   }
 }))
-export class VideoChangeOwnershipModel extends Model<VideoChangeOwnershipModel> {
+export class VideoChangeOwnershipModel extends Model<Partial<AttributesOnly<VideoChangeOwnershipModel>>> {
   @CreatedAt
   createdAt: Date
 
@@ -118,7 +119,7 @@ export class VideoChangeOwnershipModel extends Model<VideoChangeOwnershipModel>
     ]).then(([ count, rows ]) => ({ total: count, data: rows }))
   }
 
-  static load (id: number): Bluebird<MVideoChangeOwnershipFull> {
+  static load (id: number): Promise<MVideoChangeOwnershipFull> {
     return VideoChangeOwnershipModel.scope([ ScopeNames.WITH_ACCOUNTS, ScopeNames.WITH_VIDEO ])
                                     .findByPk(id)
   }
@@ -129,12 +130,7 @@ export class VideoChangeOwnershipModel extends Model<VideoChangeOwnershipModel>
       status: this.status,
       initiatorAccount: this.Initiator.toFormattedJSON(),
       nextOwnerAccount: this.NextOwner.toFormattedJSON(),
-      video: {
-        id: this.Video.id,
-        uuid: this.Video.uuid,
-        url: this.Video.url,
-        name: this.Video.name
-      },
+      video: this.Video.toFormattedJSON(),
       createdAt: this.createdAt
     }
   }