1 import * as Sequelize from 'sequelize'
3 import { addMethodsToModel, getSort } from '../utils'
5 BlacklistedVideoInstance,
6 BlacklistedVideoAttributes,
8 BlacklistedVideoMethods
9 } from './video-blacklist-interface'
11 let BlacklistedVideo: Sequelize.Model<BlacklistedVideoInstance, BlacklistedVideoAttributes>
12 let toFormattedJSON: BlacklistedVideoMethods.ToFormattedJSON
13 let countTotal: BlacklistedVideoMethods.CountTotal
14 let list: BlacklistedVideoMethods.List
15 let listForApi: BlacklistedVideoMethods.ListForApi
16 let loadById: BlacklistedVideoMethods.LoadById
17 let loadByVideoId: BlacklistedVideoMethods.LoadByVideoId
19 export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
20 BlacklistedVideo = sequelize.define<BlacklistedVideoInstance, BlacklistedVideoAttributes>('BlacklistedVideo',
25 fields: [ 'videoId' ],
32 const classMethods = [
41 const instanceMethods = [
44 addMethodsToModel(BlacklistedVideo, classMethods, instanceMethods)
46 return BlacklistedVideo
49 // ------------------------------ METHODS ------------------------------
51 toFormattedJSON = function (this: BlacklistedVideoInstance) {
54 videoId: this.videoId,
55 createdAt: this.createdAt
59 // ------------------------------ STATICS ------------------------------
61 function associate (models) {
62 BlacklistedVideo.belongsTo(models.Video, {
71 countTotal = function () {
72 return BlacklistedVideo.count()
76 return BlacklistedVideo.findAll()
79 listForApi = function (start: number, count: number, sort: string) {
83 order: [ getSort(sort) ]
86 return BlacklistedVideo.findAndCountAll(query).then(({ rows, count }) => {
94 loadById = function (id: number) {
95 return BlacklistedVideo.findById(id)
98 loadByVideoId = function (id: number) {
105 return BlacklistedVideo.findOne(query)