1 import * as Sequelize from 'sequelize'
3 import { addMethodsToModel } from '../utils'
4 import { VideoShareAttributes, VideoShareInstance, VideoShareMethods } from './video-share-interface'
6 let VideoShare: Sequelize.Model<VideoShareInstance, VideoShareAttributes>
7 let loadAccountsByShare: VideoShareMethods.LoadAccountsByShare
8 let load: VideoShareMethods.Load
10 export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
11 VideoShare = sequelize.define<VideoShareInstance, VideoShareAttributes>('VideoShare',
16 fields: [ 'accountId' ]
25 const classMethods = [
30 addMethodsToModel(VideoShare, classMethods)
35 // ------------------------------ METHODS ------------------------------
37 function associate (models) {
38 VideoShare.belongsTo(models.Account, {
46 VideoShare.belongsTo(models.Video, {
55 load = function (accountId: number, videoId: number, t: Sequelize.Transaction) {
56 return VideoShare.findOne({
62 VideoShare['sequelize'].models.Account
68 loadAccountsByShare = function (videoId: number, t: Sequelize.Transaction) {
75 model: VideoShare['sequelize'].models.Account,
82 return VideoShare.findAll(query)
83 .then(res => res.map(r => r.Account))