]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-blacklist.ts
Rename Pod -> Server
[github/Chocobozzz/PeerTube.git] / server / models / video / video-blacklist.ts
index 8c42dbc21fbb2dc74681e5bb7c9ea7e9cf17cd72..1c279b1baefdb6eaa9edbc4313b5ecf2377b3ff0 100644 (file)
@@ -1,6 +1,8 @@
 import * as Sequelize from 'sequelize'
 
-import { addMethodsToModel, getSort } from '../utils'
+import { SortType } from '../../helpers'
+import { addMethodsToModel, getSortOnModel } from '../utils'
+import { VideoInstance } from './video-interface'
 import {
   BlacklistedVideoInstance,
   BlacklistedVideoAttributes,
@@ -9,7 +11,7 @@ import {
 } from './video-blacklist-interface'
 
 let BlacklistedVideo: Sequelize.Model<BlacklistedVideoInstance, BlacklistedVideoAttributes>
-let toFormatedJSON: BlacklistedVideoMethods.ToFormatedJSON
+let toFormattedJSON: BlacklistedVideoMethods.ToFormattedJSON
 let countTotal: BlacklistedVideoMethods.CountTotal
 let list: BlacklistedVideoMethods.List
 let listForApi: BlacklistedVideoMethods.ListForApi
@@ -39,7 +41,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
     loadByVideoId
   ]
   const instanceMethods = [
-    toFormatedJSON
+    toFormattedJSON
   ]
   addMethodsToModel(BlacklistedVideo, classMethods, instanceMethods)
 
@@ -48,11 +50,24 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
 
 // ------------------------------ METHODS ------------------------------
 
-toFormatedJSON = function (this: BlacklistedVideoInstance) {
+toFormattedJSON = function (this: BlacklistedVideoInstance) {
+  let video: VideoInstance
+
+  video = this.Video
+
   return {
     id: this.id,
     videoId: this.videoId,
-    createdAt: this.createdAt
+    createdAt: this.createdAt,
+    updatedAt: this.updatedAt,
+    name: video.name,
+    uuid: video.uuid,
+    description: video.description,
+    duration: video.duration,
+    views: video.views,
+    likes: video.likes,
+    dislikes: video.dislikes,
+    nsfw: video.nsfw
   }
 }
 
@@ -60,8 +75,11 @@ toFormatedJSON = function (this: BlacklistedVideoInstance) {
 
 function associate (models) {
   BlacklistedVideo.belongsTo(models.Video, {
-    foreignKey: 'videoId',
-    onDelete: 'cascade'
+    foreignKey: {
+      name: 'videoId',
+      allowNull: false
+    },
+    onDelete: 'CASCADE'
   })
 }
 
@@ -73,11 +91,12 @@ list = function () {
   return BlacklistedVideo.findAll()
 }
 
-listForApi = function (start: number, count: number, sort: string) {
+listForApi = function (start: number, count: number, sort: SortType) {
   const query = {
     offset: start,
     limit: count,
-    order: [ getSort(sort) ]
+    order: [ getSortOnModel(sort.sortModel, sort.sortValue) ],
+    include: [ { model: BlacklistedVideo['sequelize'].models.Video } ]
   }
 
   return BlacklistedVideo.findAndCountAll(query).then(({ rows, count }) => {
@@ -92,7 +111,7 @@ loadById = function (id: number) {
   return BlacklistedVideo.findById(id)
 }
 
-loadByVideoId = function (id: string) {
+loadByVideoId = function (id: number) {
   const query = {
     where: {
       videoId: id