1 import { CONFIG } from '../initializers'
2 import { isVideoAbuseReporterUsernameValid, isVideoAbuseReasonValid } from '../helpers'
3 import { getSort } from './utils'
5 module.exports = function (sequelize, DataTypes) {
6 const VideoAbuse = sequelize.define('VideoAbuse',
9 type: DataTypes.STRING,
12 reporterUsernameValid: function (value) {
13 const res = isVideoAbuseReporterUsernameValid(value)
14 if (res === false) throw new Error('Video abuse reporter username is not valid.')
19 type: DataTypes.STRING,
22 reasonValid: function (value) {
23 const res = isVideoAbuseReasonValid(value)
24 if (res === false) throw new Error('Video abuse reason is not valid.')
35 fields: [ 'reporterPodId' ]
52 // ---------------------------------------------------------------------------
54 function associate (models) {
55 this.belongsTo(models.Pod, {
57 name: 'reporterPodId',
63 this.belongsTo(models.Video, {
72 function listForApi (start, count, sort, callback) {
76 order: [ getSort(sort) ],
79 model: this.sequelize.models.Pod,
85 return this.findAndCountAll(query).asCallback(function (err, result) {
86 if (err) return callback(err)
88 return callback(null, result.rows, result.count)
92 function toFormatedJSON () {
96 reporterPodHost = this.Pod.host
98 // It means it's our video
99 reporterPodHost = CONFIG.WEBSERVER.HOST
106 reporterUsername: this.reporterUsername,
107 videoId: this.videoId,
108 createdAt: this.createdAt