1 import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
2 import { AccountModel } from '../account/account'
3 import { VideoModel } from './video'
4 import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '../../../shared/models/videos'
5 import { getSort } from '../utils'
6 import { VideoFileModel } from './video-file'
13 tableName: 'videoChangeOwnership',
19 fields: ['initiatorAccountId']
22 fields: ['nextOwnerAccountId']
30 model: () => AccountModel,
35 model: () => AccountModel,
40 model: () => VideoModel,
43 { model: () => VideoFileModel }
49 export class VideoChangeOwnershipModel extends Model<VideoChangeOwnershipModel> {
58 status: VideoChangeOwnershipStatus
60 @ForeignKey(() => AccountModel)
62 initiatorAccountId: number
64 @BelongsTo(() => AccountModel, {
66 name: 'initiatorAccountId',
71 Initiator: AccountModel
73 @ForeignKey(() => AccountModel)
75 nextOwnerAccountId: number
77 @BelongsTo(() => AccountModel, {
79 name: 'nextOwnerAccountId',
84 NextOwner: AccountModel
86 @ForeignKey(() => VideoModel)
90 @BelongsTo(() => VideoModel, {
98 static listForApi (nextOwnerId: number, start: number, count: number, sort: string) {
102 order: getSort(sort),
104 nextOwnerAccountId: nextOwnerId
108 return VideoChangeOwnershipModel.scope(ScopeNames.FULL).findAndCountAll(query)
109 .then(({ rows, count }) => ({ total: count, data: rows }))
112 static load (id: number) {
113 return VideoChangeOwnershipModel.scope(ScopeNames.FULL).findById(id)
116 toFormattedJSON (): VideoChangeOwnership {
120 initiatorAccount: this.Initiator.toFormattedJSON(),
121 nextOwnerAccount: this.NextOwner.toFormattedJSON(),
124 uuid: this.Video.uuid,
126 name: this.Video.name
128 createdAt: this.createdAt