aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video-blacklist.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video-blacklist.ts')
-rw-r--r--server/models/video-blacklist.ts103
1 files changed, 0 insertions, 103 deletions
diff --git a/server/models/video-blacklist.ts b/server/models/video-blacklist.ts
deleted file mode 100644
index 040ed03d7..000000000
--- a/server/models/video-blacklist.ts
+++ /dev/null
@@ -1,103 +0,0 @@
1import * as Sequelize from 'sequelize'
2
3import { addMethodsToModel, getSort } from './utils'
4import {
5 BlacklistedVideoClass,
6 BlacklistedVideoInstance,
7 BlacklistedVideoAttributes,
8
9 BlacklistedVideoMethods
10} from './video-blacklist-interface'
11
12let BlacklistedVideo: Sequelize.Model<BlacklistedVideoInstance, BlacklistedVideoAttributes>
13let toFormatedJSON: BlacklistedVideoMethods.ToFormatedJSON
14let countTotal: BlacklistedVideoMethods.CountTotal
15let list: BlacklistedVideoMethods.List
16let listForApi: BlacklistedVideoMethods.ListForApi
17let loadById: BlacklistedVideoMethods.LoadById
18let loadByVideoId: BlacklistedVideoMethods.LoadByVideoId
19
20export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
21 BlacklistedVideo = sequelize.define<BlacklistedVideoInstance, BlacklistedVideoAttributes>('BlacklistedVideo',
22 {},
23 {
24 indexes: [
25 {
26 fields: [ 'videoId' ],
27 unique: true
28 }
29 ]
30 }
31 )
32
33 const classMethods = [
34 associate,
35
36 countTotal,
37 list,
38 listForApi,
39 loadById,
40 loadByVideoId
41 ]
42 const instanceMethods = [
43 toFormatedJSON
44 ]
45 addMethodsToModel(BlacklistedVideo, classMethods, instanceMethods)
46
47 return BlacklistedVideo
48}
49
50// ------------------------------ METHODS ------------------------------
51
52toFormatedJSON = function () {
53 return {
54 id: this.id,
55 videoId: this.videoId,
56 createdAt: this.createdAt
57 }
58}
59
60// ------------------------------ STATICS ------------------------------
61
62function associate (models) {
63 BlacklistedVideo.belongsTo(models.Video, {
64 foreignKey: 'videoId',
65 onDelete: 'cascade'
66 })
67}
68
69countTotal = function (callback: BlacklistedVideoMethods.CountTotalCallback) {
70 return BlacklistedVideo.count().asCallback(callback)
71}
72
73list = function (callback: BlacklistedVideoMethods.ListCallback) {
74 return BlacklistedVideo.findAll().asCallback(callback)
75}
76
77listForApi = function (start: number, count: number, sort: string, callback: BlacklistedVideoMethods.ListForApiCallback) {
78 const query = {
79 offset: start,
80 limit: count,
81 order: [ getSort(sort) ]
82 }
83
84 return BlacklistedVideo.findAndCountAll(query).asCallback(function (err, result) {
85 if (err) return callback(err)
86
87 return callback(null, result.rows, result.count)
88 })
89}
90
91loadById = function (id: number, callback: BlacklistedVideoMethods.LoadByIdCallback) {
92 return BlacklistedVideo.findById(id).asCallback(callback)
93}
94
95loadByVideoId = function (id: string, callback: BlacklistedVideoMethods.LoadByIdCallback) {
96 const query = {
97 where: {
98 videoId: id
99 }
100 }
101
102 return BlacklistedVideo.find(query).asCallback(callback)
103}