1 import * as Sequelize from 'sequelize'
2 import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
3 import { AccountModel } from '../account/account'
4 import { VideoChannelModel } from './video-channel'
8 WITH_ACCOUNT = 'WITH_ACCOUNT'
15 model: () => AccountModel,
19 model: () => VideoChannelModel,
24 [ScopeNames.WITH_ACCOUNT]: {
27 model: () => AccountModel,
34 tableName: 'videoChannelShare',
37 fields: [ 'accountId' ]
40 fields: [ 'videoChannelId' ]
44 export class VideoChannelShareModel extends Model<VideoChannelShareModel> {
51 @ForeignKey(() => AccountModel)
55 @BelongsTo(() => AccountModel, {
63 @ForeignKey(() => VideoChannelModel)
65 videoChannelId: number
67 @BelongsTo(() => VideoChannelModel, {
73 VideoChannel: VideoChannelModel
75 static load (accountId: number, videoChannelId: number, t: Sequelize.Transaction) {
76 return VideoChannelShareModel.scope(ScopeNames.FULL).findOne({
85 static loadAccountsByShare (videoChannelId: number, t: Sequelize.Transaction) {
93 return VideoChannelShareModel.scope(ScopeNames.WITH_ACCOUNT).findAll(query)
94 .then(res => res.map(r => r.Account))