1 import * as Sequelize from 'sequelize'
3 import { addMethodsToModel, getSort } from './utils'
6 BlacklistedVideoInstance,
7 BlacklistedVideoAttributes,
9 BlacklistedVideoMethods
10 } from './video-blacklist-interface'
12 let BlacklistedVideo: Sequelize.Model<BlacklistedVideoInstance, BlacklistedVideoAttributes>
13 let toFormatedJSON: BlacklistedVideoMethods.ToFormatedJSON
14 let countTotal: BlacklistedVideoMethods.CountTotal
15 let list: BlacklistedVideoMethods.List
16 let listForApi: BlacklistedVideoMethods.ListForApi
17 let loadById: BlacklistedVideoMethods.LoadById
18 let loadByVideoId: BlacklistedVideoMethods.LoadByVideoId
20 export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
21 BlacklistedVideo = sequelize.define<BlacklistedVideoInstance, BlacklistedVideoAttributes>('BlacklistedVideo',
26 fields: [ 'videoId' ],
33 const classMethods = [
42 const instanceMethods = [
45 addMethodsToModel(BlacklistedVideo, classMethods, instanceMethods)
47 return BlacklistedVideo
50 // ------------------------------ METHODS ------------------------------
52 toFormatedJSON = function () {
55 videoId: this.videoId,
56 createdAt: this.createdAt
60 // ------------------------------ STATICS ------------------------------
62 function associate (models) {
63 BlacklistedVideo.belongsTo(models.Video, {
64 foreignKey: 'videoId',
69 countTotal = function (callback: BlacklistedVideoMethods.CountTotalCallback) {
70 return BlacklistedVideo.count().asCallback(callback)
73 list = function (callback: BlacklistedVideoMethods.ListCallback) {
74 return BlacklistedVideo.findAll().asCallback(callback)
77 listForApi = function (start: number, count: number, sort: string, callback: BlacklistedVideoMethods.ListForApiCallback) {
81 order: [ getSort(sort) ]
84 return BlacklistedVideo.findAndCountAll(query).asCallback(function (err, result) {
85 if (err) return callback(err)
87 return callback(null, result.rows, result.count)
91 loadById = function (id: number, callback: BlacklistedVideoMethods.LoadByIdCallback) {
92 return BlacklistedVideo.findById(id).asCallback(callback)
95 loadByVideoId = function (id: string, callback: BlacklistedVideoMethods.LoadByIdCallback) {
102 return BlacklistedVideo.find(query).asCallback(callback)