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 countTotal: BlacklistedVideoMethods.CountTotal
16 let list: BlacklistedVideoMethods.List
17 let listForApi: BlacklistedVideoMethods.ListForApi
18 let loadById: BlacklistedVideoMethods.LoadById
19 let loadByVideoId: BlacklistedVideoMethods.LoadByVideoId
21 export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
22 BlacklistedVideo = sequelize.define<BlacklistedVideoInstance, BlacklistedVideoAttributes>('BlacklistedVideo',
27 fields: [ 'videoId' ],
34 const classMethods = [
43 const instanceMethods = [
46 addMethodsToModel(BlacklistedVideo, classMethods, instanceMethods)
48 return BlacklistedVideo
51 // ------------------------------ METHODS ------------------------------
53 toFormattedJSON = function (this: BlacklistedVideoInstance) {
54 let video: VideoInstance
60 videoId: this.videoId,
61 createdAt: this.createdAt,
62 updatedAt: this.updatedAt,
65 description: video.description,
66 duration: video.duration,
69 dislikes: video.dislikes,
74 // ------------------------------ STATICS ------------------------------
76 function associate (models) {
77 BlacklistedVideo.belongsTo(models.Video, {
86 countTotal = function () {
87 return BlacklistedVideo.count()
91 return BlacklistedVideo.findAll()
94 listForApi = function (start: number, count: number, sort: SortType) {
98 order: [ getSortOnModel(sort.sortModel, sort.sortValue) ],
99 include: [ { model: BlacklistedVideo['sequelize'].models.Video } ]
102 return BlacklistedVideo.findAndCountAll(query).then(({ rows, count }) => {
110 loadById = function (id: number) {
111 return BlacklistedVideo.findById(id)
114 loadByVideoId = function (id: number) {
121 return BlacklistedVideo.findOne(query)