diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-05-15 22:22:03 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-05-20 09:57:40 +0200 |
commit | 65fcc3119c334b75dd13bcfdebf186afdc580a8f (patch) | |
tree | 4f2158c61a9b7c3f47cfa233d01413b946ee53c0 /server/models/video-abuse.js | |
parent | d5f345ed4cfac4e1fa84dcb4fce1cda4d32f9c73 (diff) | |
download | PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.gz PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.zst PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.zip |
First typescript iteration
Diffstat (limited to 'server/models/video-abuse.js')
-rw-r--r-- | server/models/video-abuse.js | 114 |
1 files changed, 0 insertions, 114 deletions
diff --git a/server/models/video-abuse.js b/server/models/video-abuse.js deleted file mode 100644 index 67cead3af..000000000 --- a/server/models/video-abuse.js +++ /dev/null | |||
@@ -1,114 +0,0 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const constants = require('../initializers/constants') | ||
4 | const modelUtils = require('./utils') | ||
5 | const customVideosValidators = require('../helpers/custom-validators').videos | ||
6 | |||
7 | module.exports = function (sequelize, DataTypes) { | ||
8 | const VideoAbuse = sequelize.define('VideoAbuse', | ||
9 | { | ||
10 | reporterUsername: { | ||
11 | type: DataTypes.STRING, | ||
12 | allowNull: false, | ||
13 | validate: { | ||
14 | reporterUsernameValid: function (value) { | ||
15 | const res = customVideosValidators.isVideoAbuseReporterUsernameValid(value) | ||
16 | if (res === false) throw new Error('Video abuse reporter username is not valid.') | ||
17 | } | ||
18 | } | ||
19 | }, | ||
20 | reason: { | ||
21 | type: DataTypes.STRING, | ||
22 | allowNull: false, | ||
23 | validate: { | ||
24 | reasonValid: function (value) { | ||
25 | const res = customVideosValidators.isVideoAbuseReasonValid(value) | ||
26 | if (res === false) throw new Error('Video abuse reason is not valid.') | ||
27 | } | ||
28 | } | ||
29 | } | ||
30 | }, | ||
31 | { | ||
32 | indexes: [ | ||
33 | { | ||
34 | fields: [ 'videoId' ] | ||
35 | }, | ||
36 | { | ||
37 | fields: [ 'reporterPodId' ] | ||
38 | } | ||
39 | ], | ||
40 | classMethods: { | ||
41 | associate, | ||
42 | |||
43 | listForApi | ||
44 | }, | ||
45 | instanceMethods: { | ||
46 | toFormatedJSON | ||
47 | } | ||
48 | } | ||
49 | ) | ||
50 | |||
51 | return VideoAbuse | ||
52 | } | ||
53 | |||
54 | // --------------------------------------------------------------------------- | ||
55 | |||
56 | function associate (models) { | ||
57 | this.belongsTo(models.Pod, { | ||
58 | foreignKey: { | ||
59 | name: 'reporterPodId', | ||
60 | allowNull: true | ||
61 | }, | ||
62 | onDelete: 'cascade' | ||
63 | }) | ||
64 | |||
65 | this.belongsTo(models.Video, { | ||
66 | foreignKey: { | ||
67 | name: 'videoId', | ||
68 | allowNull: false | ||
69 | }, | ||
70 | onDelete: 'cascade' | ||
71 | }) | ||
72 | } | ||
73 | |||
74 | function listForApi (start, count, sort, callback) { | ||
75 | const query = { | ||
76 | offset: start, | ||
77 | limit: count, | ||
78 | order: [ modelUtils.getSort(sort) ], | ||
79 | include: [ | ||
80 | { | ||
81 | model: this.sequelize.models.Pod, | ||
82 | required: false | ||
83 | } | ||
84 | ] | ||
85 | } | ||
86 | |||
87 | return this.findAndCountAll(query).asCallback(function (err, result) { | ||
88 | if (err) return callback(err) | ||
89 | |||
90 | return callback(null, result.rows, result.count) | ||
91 | }) | ||
92 | } | ||
93 | |||
94 | function toFormatedJSON () { | ||
95 | let reporterPodHost | ||
96 | |||
97 | if (this.Pod) { | ||
98 | reporterPodHost = this.Pod.host | ||
99 | } else { | ||
100 | // It means it's our video | ||
101 | reporterPodHost = constants.CONFIG.WEBSERVER.HOST | ||
102 | } | ||
103 | |||
104 | const json = { | ||
105 | id: this.id, | ||
106 | reporterPodHost, | ||
107 | reason: this.reason, | ||
108 | reporterUsername: this.reporterUsername, | ||
109 | videoId: this.videoId, | ||
110 | createdAt: this.createdAt | ||
111 | } | ||
112 | |||
113 | return json | ||
114 | } | ||