1 import * as Sequelize from 'sequelize'
3 import { SortType } from '../../helpers'
4 import { addMethodsToModel, getSortOnModel } from '../utils'
5 import { VideoInstance } from './video-interface'
7 BlacklistedVideoInstance,
8 BlacklistedVideoAttributes,
10 BlacklistedVideoMethods
11 } from './video-blacklist-interface'
13 let BlacklistedVideo: Sequelize.Model<BlacklistedVideoInstance, BlacklistedVideoAttributes>
14 let toFormattedJSON: BlacklistedVideoMethods.ToFormattedJSON
15 let listForApi: BlacklistedVideoMethods.ListForApi
16 let loadByVideoId: BlacklistedVideoMethods.LoadByVideoId
18 export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
19 BlacklistedVideo = sequelize.define<BlacklistedVideoInstance, BlacklistedVideoAttributes>('BlacklistedVideo',
24 fields: [ 'videoId' ],
31 const classMethods = [
37 const instanceMethods = [
40 addMethodsToModel(BlacklistedVideo, classMethods, instanceMethods)
42 return BlacklistedVideo
45 // ------------------------------ METHODS ------------------------------
47 toFormattedJSON = function (this: BlacklistedVideoInstance) {
48 let video: VideoInstance
54 videoId: this.videoId,
55 createdAt: this.createdAt,
56 updatedAt: this.updatedAt,
59 description: video.description,
60 duration: video.duration,
63 dislikes: video.dislikes,
68 // ------------------------------ STATICS ------------------------------
70 function associate (models) {
71 BlacklistedVideo.belongsTo(models.Video, {
80 listForApi = function (start: number, count: number, sort: SortType) {
84 order: [ getSortOnModel(sort.sortModel, sort.sortValue) ],
85 include: [ { model: BlacklistedVideo['sequelize'].models.Video } ]
88 return BlacklistedVideo.findAndCountAll(query).then(({ rows, count }) => {
96 loadByVideoId = function (id: number) {
103 return BlacklistedVideo.findOne(query)