import { addMethodsToModel, getSort } from '../utils'
import {
- VideoAbuseClass,
VideoAbuseInstance,
VideoAbuseAttributes,
} from './video-abuse-interface'
let VideoAbuse: Sequelize.Model<VideoAbuseInstance, VideoAbuseAttributes>
+let toFormattedJSON: VideoAbuseMethods.ToFormattedJSON
let listForApi: VideoAbuseMethods.ListForApi
export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
type: DataTypes.STRING,
allowNull: false,
validate: {
- reporterUsernameValid: function (value) {
+ reporterUsernameValid: value => {
const res = isVideoAbuseReporterUsernameValid(value)
if (res === false) throw new Error('Video abuse reporter username is not valid.')
}
type: DataTypes.STRING,
allowNull: false,
validate: {
- reasonValid: function (value) {
+ reasonValid: value => {
const res = isVideoAbuseReasonValid(value)
if (res === false) throw new Error('Video abuse reason is not valid.')
}
fields: [ 'videoId' ]
},
{
- fields: [ 'reporterPodId' ]
+ fields: [ 'reporterServerId' ]
}
]
}
listForApi
]
const instanceMethods = [
- toFormatedJSON
+ toFormattedJSON
]
addMethodsToModel(VideoAbuse, classMethods, instanceMethods)
// ------------------------------ METHODS ------------------------------
-function toFormatedJSON () {
- let reporterPodHost
+toFormattedJSON = function (this: VideoAbuseInstance) {
+ let reporterServerHost
- if (this.Pod) {
- reporterPodHost = this.Pod.host
+ if (this.Server) {
+ reporterServerHost = this.Server.host
} else {
// It means it's our video
- reporterPodHost = CONFIG.WEBSERVER.HOST
+ reporterServerHost = CONFIG.WEBSERVER.HOST
}
const json = {
id: this.id,
- reporterPodHost,
+ reporterServerHost,
reason: this.reason,
reporterUsername: this.reporterUsername,
videoId: this.videoId,
// ------------------------------ STATICS ------------------------------
function associate (models) {
- VideoAbuse.belongsTo(models.Pod, {
+ VideoAbuse.belongsTo(models.Server, {
foreignKey: {
- name: 'reporterPodId',
+ name: 'reporterServerId',
allowNull: true
},
- onDelete: 'cascade'
+ onDelete: 'CASCADE'
})
VideoAbuse.belongsTo(models.Video, {
name: 'videoId',
allowNull: false
},
- onDelete: 'cascade'
+ onDelete: 'CASCADE'
})
}
-listForApi = function (start, count, sort, callback) {
+listForApi = function (start: number, count: number, sort: string) {
const query = {
offset: start,
limit: count,
order: [ getSort(sort) ],
include: [
{
- model: VideoAbuse['sequelize'].models.Pod,
+ model: VideoAbuse['sequelize'].models.Server,
required: false
}
]
}
- return VideoAbuse.findAndCountAll(query).asCallback(function (err, result) {
- if (err) return callback(err)
-
- return callback(null, result.rows, result.count)
+ return VideoAbuse.findAndCountAll(query).then(({ rows, count }) => {
+ return { total: count, data: rows }
})
}
-
-