1 import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
2 import { AccountModel } from '../account/account'
3 import { ScopeNames as VideoScopeNames, VideoModel } from './video'
4 import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '../../../shared/models/videos'
5 import { getSort } from '../utils'
8 WITH_ACCOUNTS = 'WITH_ACCOUNTS',
9 WITH_VIDEO = 'WITH_VIDEO'
13 tableName: 'videoChangeOwnership',
19 fields: [ 'initiatorAccountId' ]
22 fields: [ 'nextOwnerAccountId' ]
27 [ScopeNames.WITH_ACCOUNTS]: {
41 [ScopeNames.WITH_VIDEO]: {
44 model: VideoModel.scope([ VideoScopeNames.WITH_THUMBNAILS, VideoScopeNames.WITH_FILES ]),
50 export class VideoChangeOwnershipModel extends Model<VideoChangeOwnershipModel> {
59 status: VideoChangeOwnershipStatus
61 @ForeignKey(() => AccountModel)
63 initiatorAccountId: number
65 @BelongsTo(() => AccountModel, {
67 name: 'initiatorAccountId',
72 Initiator: AccountModel
74 @ForeignKey(() => AccountModel)
76 nextOwnerAccountId: number
78 @BelongsTo(() => AccountModel, {
80 name: 'nextOwnerAccountId',
85 NextOwner: AccountModel
87 @ForeignKey(() => VideoModel)
91 @BelongsTo(() => VideoModel, {
99 static listForApi (nextOwnerId: number, start: number, count: number, sort: string) {
103 order: getSort(sort),
105 nextOwnerAccountId: nextOwnerId
110 VideoChangeOwnershipModel.scope(ScopeNames.WITH_ACCOUNTS).count(query),
111 VideoChangeOwnershipModel.scope([ ScopeNames.WITH_ACCOUNTS, ScopeNames.WITH_VIDEO ]).findAll(query)
112 ]).then(([ count, rows ]) => ({ total: count, data: rows }))
115 static load (id: number) {
116 return VideoChangeOwnershipModel.scope([ ScopeNames.WITH_ACCOUNTS, ScopeNames.WITH_VIDEO ])
120 toFormattedJSON (): VideoChangeOwnership {
124 initiatorAccount: this.Initiator.toFormattedJSON(),
125 nextOwnerAccount: this.NextOwner.toFormattedJSON(),
128 uuid: this.Video.uuid,
130 name: this.Video.name
132 createdAt: this.createdAt