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/typescript-utils'
import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '../../../shared/models/videos'
+import { AccountModel } from '../account/account'
import { getSort } from '../utils'
+import { ScopeNames as VideoScopeNames, VideoModel } from './video'
enum ScopeNames {
WITH_ACCOUNTS = 'WITH_ACCOUNTS',
[ScopeNames.WITH_VIDEO]: {
include: [
{
- model: VideoModel.scope([ VideoScopeNames.WITH_THUMBNAILS, VideoScopeNames.WITH_FILES ]),
+ model: VideoModel.scope([
+ VideoScopeNames.WITH_THUMBNAILS,
+ VideoScopeNames.WITH_WEBTORRENT_FILES,
+ 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
return Promise.all([
VideoChangeOwnershipModel.scope(ScopeNames.WITH_ACCOUNTS).count(query),
- VideoChangeOwnershipModel.scope([ ScopeNames.WITH_ACCOUNTS, ScopeNames.WITH_VIDEO ]).findAll(query)
+ VideoChangeOwnershipModel.scope([ ScopeNames.WITH_ACCOUNTS, ScopeNames.WITH_VIDEO ]).findAll<MVideoChangeOwnershipFull>(query)
]).then(([ count, rows ]) => ({ total: count, data: rows }))
}
- static load (id: number) {
+ static load (id: number): Promise<MVideoChangeOwnershipFull> {
return VideoChangeOwnershipModel.scope([ ScopeNames.WITH_ACCOUNTS, ScopeNames.WITH_VIDEO ])
.findByPk(id)
}
- toFormattedJSON (): VideoChangeOwnership {
+ toFormattedJSON (this: MVideoChangeOwnershipFormattable): VideoChangeOwnership {
return {
id: this.id,
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
}
}