]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-abuse.ts
Move to promises
[github/Chocobozzz/PeerTube.git] / server / models / video / video-abuse.ts
index e0e0bcfe6d66329e7b82d05764cf886bb7f544f7..ab1a3ea7d393d6b3970e7e1b8a9ffdbee70209a4 100644 (file)
@@ -5,7 +5,6 @@ import { isVideoAbuseReporterUsernameValid, isVideoAbuseReasonValid } from '../.
 
 import { addMethodsToModel, getSort } from '../utils'
 import {
-  VideoAbuseClass,
   VideoAbuseInstance,
   VideoAbuseAttributes,
 
@@ -13,6 +12,7 @@ import {
 } from './video-abuse-interface'
 
 let VideoAbuse: Sequelize.Model<VideoAbuseInstance, VideoAbuseAttributes>
+let toFormatedJSON: VideoAbuseMethods.ToFormatedJSON
 let listForApi: VideoAbuseMethods.ListForApi
 
 export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
@@ -66,7 +66,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
 
 // ------------------------------ METHODS ------------------------------
 
-function toFormatedJSON () {
+toFormatedJSON = function (this: VideoAbuseInstance) {
   let reporterPodHost
 
   if (this.Pod) {
@@ -108,7 +108,7 @@ function associate (models) {
   })
 }
 
-listForApi = function (start, count, sort, callback) {
+listForApi = function (start: number, count: number, sort: string) {
   const query = {
     offset: start,
     limit: count,
@@ -121,11 +121,7 @@ listForApi = function (start, count, sort, callback) {
     ]
   }
 
-  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 }
   })
 }
-
-