X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-blacklist.ts;h=ae8286285cd1bb37d1a29591625fc27834f7c8eb;hb=c893d4514e6ecbf282c7985fe5f82b8acd8a1137;hp=4d1b45aa57d91a7626055a76db6f8557a9403501;hpb=0a6658fdcbd779ada8f3758048c326e997902d5a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-blacklist.ts b/server/models/video/video-blacklist.ts index 4d1b45aa5..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, @@ -9,11 +11,8 @@ import { } from './video-blacklist-interface' let BlacklistedVideo: Sequelize.Model -let toFormatedJSON: BlacklistedVideoMethods.ToFormatedJSON -let countTotal: BlacklistedVideoMethods.CountTotal -let list: BlacklistedVideoMethods.List +let toFormattedJSON: BlacklistedVideoMethods.ToFormattedJSON let listForApi: BlacklistedVideoMethods.ListForApi -let loadById: BlacklistedVideoMethods.LoadById let loadByVideoId: BlacklistedVideoMethods.LoadByVideoId export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { @@ -32,14 +31,11 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da const classMethods = [ associate, - countTotal, - list, listForApi, - loadById, loadByVideoId ] const instanceMethods = [ - toFormatedJSON + toFormattedJSON ] addMethodsToModel(BlacklistedVideo, classMethods, instanceMethods) @@ -48,11 +44,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 } } @@ -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: {