aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video-abuse.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-06-16 09:45:46 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-06-16 09:45:46 +0200
commit74889a71fe687dda74f2a687653122327807af36 (patch)
treee938e8b6401b74fbec80513a877d9967f2c0dbcd /server/models/video-abuse.ts
parent15a302943d84bc0978b84fe33110c4daa451d311 (diff)
downloadPeerTube-74889a71fe687dda74f2a687653122327807af36.tar.gz
PeerTube-74889a71fe687dda74f2a687653122327807af36.tar.zst
PeerTube-74889a71fe687dda74f2a687653122327807af36.zip
Reorganize model files
Diffstat (limited to 'server/models/video-abuse.ts')
-rw-r--r--server/models/video-abuse.ts131
1 files changed, 0 insertions, 131 deletions
diff --git a/server/models/video-abuse.ts b/server/models/video-abuse.ts
deleted file mode 100644
index 5602ef968..000000000
--- a/server/models/video-abuse.ts
+++ /dev/null
@@ -1,131 +0,0 @@
1import * as Sequelize from 'sequelize'
2
3import { CONFIG } from '../initializers'
4import { isVideoAbuseReporterUsernameValid, isVideoAbuseReasonValid } from '../helpers'
5
6import { addMethodsToModel, getSort } from './utils'
7import {
8 VideoAbuseClass,
9 VideoAbuseInstance,
10 VideoAbuseAttributes,
11
12 VideoAbuseMethods
13} from './video-abuse-interface'
14
15let VideoAbuse: Sequelize.Model<VideoAbuseInstance, VideoAbuseAttributes>
16let listForApi: VideoAbuseMethods.ListForApi
17
18export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
19 VideoAbuse = sequelize.define<VideoAbuseInstance, VideoAbuseAttributes>('VideoAbuse',
20 {
21 reporterUsername: {
22 type: DataTypes.STRING,
23 allowNull: false,
24 validate: {
25 reporterUsernameValid: function (value) {
26 const res = isVideoAbuseReporterUsernameValid(value)
27 if (res === false) throw new Error('Video abuse reporter username is not valid.')
28 }
29 }
30 },
31 reason: {
32 type: DataTypes.STRING,
33 allowNull: false,
34 validate: {
35 reasonValid: function (value) {
36 const res = isVideoAbuseReasonValid(value)
37 if (res === false) throw new Error('Video abuse reason is not valid.')
38 }
39 }
40 }
41 },
42 {
43 indexes: [
44 {
45 fields: [ 'videoId' ]
46 },
47 {
48 fields: [ 'reporterPodId' ]
49 }
50 ]
51 }
52 )
53
54 const classMethods = [
55 associate,
56
57 listForApi
58 ]
59 const instanceMethods = [
60 toFormatedJSON
61 ]
62 addMethodsToModel(VideoAbuse, classMethods, instanceMethods)
63
64 return VideoAbuse
65}
66
67// ------------------------------ METHODS ------------------------------
68
69function toFormatedJSON () {
70 let reporterPodHost
71
72 if (this.Pod) {
73 reporterPodHost = this.Pod.host
74 } else {
75 // It means it's our video
76 reporterPodHost = CONFIG.WEBSERVER.HOST
77 }
78
79 const json = {
80 id: this.id,
81 reporterPodHost,
82 reason: this.reason,
83 reporterUsername: this.reporterUsername,
84 videoId: this.videoId,
85 createdAt: this.createdAt
86 }
87
88 return json
89}
90
91// ------------------------------ STATICS ------------------------------
92
93function associate (models) {
94 VideoAbuse.belongsTo(models.Pod, {
95 foreignKey: {
96 name: 'reporterPodId',
97 allowNull: true
98 },
99 onDelete: 'cascade'
100 })
101
102 VideoAbuse.belongsTo(models.Video, {
103 foreignKey: {
104 name: 'videoId',
105 allowNull: false
106 },
107 onDelete: 'cascade'
108 })
109}
110
111listForApi = function (start, count, sort, callback) {
112 const query = {
113 offset: start,
114 limit: count,
115 order: [ getSort(sort) ],
116 include: [
117 {
118 model: VideoAbuse['sequelize'].models.Pod,
119 required: false
120 }
121 ]
122 }
123
124 return VideoAbuse.findAndCountAll(query).asCallback(function (err, result) {
125 if (err) return callback(err)
126
127 return callback(null, result.rows, result.count)
128 })
129}
130
131