aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video-blacklist.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-05-15 22:22:03 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-05-20 09:57:40 +0200
commit65fcc3119c334b75dd13bcfdebf186afdc580a8f (patch)
tree4f2158c61a9b7c3f47cfa233d01413b946ee53c0 /server/models/video-blacklist.ts
parentd5f345ed4cfac4e1fa84dcb4fce1cda4d32f9c73 (diff)
downloadPeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.gz
PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.zst
PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.zip
First typescript iteration
Diffstat (limited to 'server/models/video-blacklist.ts')
-rw-r--r--server/models/video-blacklist.ts87
1 files changed, 87 insertions, 0 deletions
diff --git a/server/models/video-blacklist.ts b/server/models/video-blacklist.ts
new file mode 100644
index 000000000..1f00702c7
--- /dev/null
+++ b/server/models/video-blacklist.ts
@@ -0,0 +1,87 @@
1import { getSort } from './utils'
2
3// ---------------------------------------------------------------------------
4
5module.exports = function (sequelize, DataTypes) {
6 const BlacklistedVideo = sequelize.define('BlacklistedVideo',
7 {},
8 {
9 indexes: [
10 {
11 fields: [ 'videoId' ],
12 unique: true
13 }
14 ],
15 classMethods: {
16 associate,
17
18 countTotal,
19 list,
20 listForApi,
21 loadById,
22 loadByVideoId
23 },
24 instanceMethods: {
25 toFormatedJSON
26 },
27 hooks: {}
28 }
29 )
30
31 return BlacklistedVideo
32}
33
34// ------------------------------ METHODS ------------------------------
35
36function toFormatedJSON () {
37 return {
38 id: this.id,
39 videoId: this.videoId,
40 createdAt: this.createdAt
41 }
42}
43
44// ------------------------------ STATICS ------------------------------
45
46function associate (models) {
47 this.belongsTo(models.Video, {
48 foreignKey: 'videoId',
49 onDelete: 'cascade'
50 })
51}
52
53function countTotal (callback) {
54 return this.count().asCallback(callback)
55}
56
57function list (callback) {
58 return this.findAll().asCallback(callback)
59}
60
61function listForApi (start, count, sort, callback) {
62 const query = {
63 offset: start,
64 limit: count,
65 order: [ getSort(sort) ]
66 }
67
68 return this.findAndCountAll(query).asCallback(function (err, result) {
69 if (err) return callback(err)
70
71 return callback(null, result.rows, result.count)
72 })
73}
74
75function loadById (id, callback) {
76 return this.findById(id).asCallback(callback)
77}
78
79function loadByVideoId (id, callback) {
80 const query = {
81 where: {
82 videoId: id
83 }
84 }
85
86 return this.find(query).asCallback(callback)
87}