import * as Sequelize from 'sequelize'
import { addMethodsToModel } from '../utils'
-import { VideoShareAttributes, VideoShareInstance } from './video-share-interface'
+import { VideoShareAttributes, VideoShareInstance, VideoShareMethods } from './video-share-interface'
let VideoShare: Sequelize.Model<VideoShareInstance, VideoShareAttributes>
+let loadAccountsByShare: VideoShareMethods.LoadAccountsByShare
export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
VideoShare = sequelize.define<VideoShareInstance, VideoShareAttributes>('VideoShare',
)
const classMethods = [
- associate
+ associate,
+ loadAccountsByShare
]
addMethodsToModel(VideoShare, classMethods)
onDelete: 'cascade'
})
}
+
+loadAccountsByShare = function (videoId: number) {
+ const query = {
+ where: {
+ videoId
+ },
+ include: [
+ {
+ model: VideoShare['sequelize'].models.Account,
+ required: true
+ }
+ ]
+ }
+
+ return VideoShare.findAll(query)
+ .then(res => res.map(r => r.Account))
+}