]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-blacklist.ts
Add previews cache system between pods
[github/Chocobozzz/PeerTube.git] / server / models / video / video-blacklist.ts
index 3576c96f6c108e2123ef9fc1f9900c508a483540..4d1b45aa57d91a7626055a76db6f8557a9403501 100644 (file)
@@ -2,7 +2,6 @@ import * as Sequelize from 'sequelize'
 
 import { addMethodsToModel, getSort } from '../utils'
 import {
-  BlacklistedVideoClass,
   BlacklistedVideoInstance,
   BlacklistedVideoAttributes,
 
@@ -61,43 +60,47 @@ toFormatedJSON = function (this: BlacklistedVideoInstance) {
 
 function associate (models) {
   BlacklistedVideo.belongsTo(models.Video, {
-    foreignKey: 'videoId',
-    onDelete: 'cascade'
+    foreignKey: {
+      name: 'videoId',
+      allowNull: false
+    },
+    onDelete: 'CASCADE'
   })
 }
 
-countTotal = function (callback: BlacklistedVideoMethods.CountTotalCallback) {
-  return BlacklistedVideo.count().asCallback(callback)
+countTotal = function () {
+  return BlacklistedVideo.count()
 }
 
-list = function (callback: BlacklistedVideoMethods.ListCallback) {
-  return BlacklistedVideo.findAll().asCallback(callback)
+list = function () {
+  return BlacklistedVideo.findAll()
 }
 
-listForApi = function (start: number, count: number, sort: string, callback: BlacklistedVideoMethods.ListForApiCallback) {
+listForApi = function (start: number, count: number, sort: string) {
   const query = {
     offset: start,
     limit: count,
     order: [ getSort(sort) ]
   }
 
-  return BlacklistedVideo.findAndCountAll(query).asCallback(function (err, result) {
-    if (err) return callback(err)
-
-    return callback(null, result.rows, result.count)
+  return BlacklistedVideo.findAndCountAll(query).then(({ rows, count }) => {
+    return {
+      data: rows,
+      total: count
+    }
   })
 }
 
-loadById = function (id: number, callback: BlacklistedVideoMethods.LoadByIdCallback) {
-  return BlacklistedVideo.findById(id).asCallback(callback)
+loadById = function (id: number) {
+  return BlacklistedVideo.findById(id)
 }
 
-loadByVideoId = function (id: string, callback: BlacklistedVideoMethods.LoadByIdCallback) {
+loadByVideoId = function (id: number) {
   const query = {
     where: {
       videoId: id
     }
   }
 
-  return BlacklistedVideo.find(query).asCallback(callback)
+  return BlacklistedVideo.findOne(query)
 }