X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-blacklist.ts;h=ae8286285cd1bb37d1a29591625fc27834f7c8eb;hb=c893d4514e6ecbf282c7985fe5f82b8acd8a1137;hp=dc49852b66a3ca8e239bd6ca61310ecf527c91b6;hpb=0aef76c479bc7fc758e70e1cd478ade46761b51b;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-blacklist.ts b/server/models/video/video-blacklist.ts index dc49852b6..ae8286285 100644 --- a/server/models/video/video-blacklist.ts +++ b/server/models/video/video-blacklist.ts @@ -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, @@ -10,10 +12,7 @@ import { let BlacklistedVideo: Sequelize.Model let toFormattedJSON: BlacklistedVideoMethods.ToFormattedJSON -let countTotal: BlacklistedVideoMethods.CountTotal -let list: BlacklistedVideoMethods.List let listForApi: BlacklistedVideoMethods.ListForApi -let loadById: BlacklistedVideoMethods.LoadById let loadByVideoId: BlacklistedVideoMethods.LoadByVideoId export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { @@ -32,10 +31,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da const classMethods = [ associate, - countTotal, - list, listForApi, - loadById, loadByVideoId ] const instanceMethods = [ @@ -49,10 +45,23 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da // ------------------------------ METHODS ------------------------------ 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 } } @@ -68,19 +77,12 @@ function associate (models) { }) } -countTotal = function () { - return BlacklistedVideo.count() -} - -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 }) => { @@ -91,10 +93,6 @@ listForApi = function (start: number, count: number, sort: string) { }) } -loadById = function (id: number) { - return BlacklistedVideo.findById(id) -} - loadByVideoId = function (id: number) { const query = { where: {