1 import * as Sequelize from 'sequelize'
3 import { addMethodsToModel } from '../utils'
4 import { VideoChannelShareAttributes, VideoChannelShareInstance, VideoChannelShareMethods } from './video-channel-share-interface'
6 let VideoChannelShare: Sequelize.Model<VideoChannelShareInstance, VideoChannelShareAttributes>
7 let loadAccountsByShare: VideoChannelShareMethods.LoadAccountsByShare
8 let load: VideoChannelShareMethods.Load
10 export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
11 VideoChannelShare = sequelize.define<VideoChannelShareInstance, VideoChannelShareAttributes>('VideoChannelShare',
16 fields: [ 'accountId' ]
19 fields: [ 'videoChannelId' ]
25 const classMethods = [
30 addMethodsToModel(VideoChannelShare, classMethods)
32 return VideoChannelShare
35 // ------------------------------ METHODS ------------------------------
37 function associate (models) {
38 VideoChannelShare.belongsTo(models.Account, {
46 VideoChannelShare.belongsTo(models.VideoChannel, {
48 name: 'videoChannelId',
55 load = function (accountId: number, videoChannelId: number, t: Sequelize.Transaction) {
56 return VideoChannelShare.findOne({
62 VideoChannelShare['sequelize'].models.Account,
63 VideoChannelShare['sequelize'].models.VideoChannel
69 loadAccountsByShare = function (videoChannelId: number, t: Sequelize.Transaction) {
76 model: VideoChannelShare['sequelize'].models.Account,
83 return VideoChannelShare.findAll(query)
84 .then(res => res.map(r => r.Account))