]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/models/video-abuse.js
3 const constants
= require('../initializers/constants')
4 const modelUtils
= require('./utils')
5 const customVideosValidators
= require('../helpers/custom-validators').videos
7 module
.exports = function (sequelize
, DataTypes
) {
8 const VideoAbuse
= sequelize
.define('VideoAbuse',
11 type: DataTypes
.STRING
,
14 reporterUsernameValid: function (value
) {
15 const res
= customVideosValidators
.isVideoAbuseReporterUsernameValid(value
)
16 if (res
=== false) throw new Error('Video abuse reporter username is not valid.')
21 type: DataTypes
.STRING
,
24 reasonValid: function (value
) {
25 const res
= customVideosValidators
.isVideoAbuseReasonValid(value
)
26 if (res
=== false) throw new Error('Video abuse reason is not valid.')
37 fields: [ 'reporterPodId' ]
54 // ---------------------------------------------------------------------------
56 function associate (models
) {
57 this.belongsTo(models
.Pod
, {
59 name: 'reporterPodId',
65 this.belongsTo(models
.Video
, {
74 function listForApi (start
, count
, sort
, callback
) {
78 order: [ modelUtils
.getSort(sort
) ],
81 model: this.sequelize
.models
.Pod
,
87 return this.findAndCountAll(query
).asCallback(function (err
, result
) {
88 if (err
) return callback(err
)
90 return callback(null, result
.rows
, result
.count
)
94 function toFormatedJSON () {
98 reporterPodHost
= this.Pod
.host
100 // It means it's our video
101 reporterPodHost
= constants
.CONFIG
.WEBSERVER
.HOST
108 reporterUsername: this.reporterUsername
,
109 videoId: this.videoId
,
110 createdAt: this.createdAt