From 792dbaf07f83fbe3f1d209cd9edf190442c7d2f3 Mon Sep 17 00:00:00 2001 From: Green-Star Date: Fri, 22 Sep 2017 09:13:43 +0200 Subject: Handle blacklist (#84) * Client: Add list blacklist feature * Server: Add list blacklist feature * Client: Add videoId column * Server: Add some video infos in the REST api * Client: Add video information in the blacklist list * Fix sortable columns :) * Client: Add removeFromBlacklist feature * Server: Add removeFromBlacklist feature * Move to TypeScript * Move to TypeScript and Promises * Server: Fix blacklist list sort * Server: Fetch videos informations * Use common shared interface for client and server * Add check-params remove blacklisted video tests * Add check-params list blacklisted videos tests * Add list blacklist tests * Add remove from blacklist tests * Add video blacklist management tests * Fix rebase onto develop issues * Server: Add sort on blacklist id column * Server: Add blacklists library * Add blacklist id sort test * Add check-params tests for blacklist list pagination, count and sort * Fix coding style * Increase Remote API tests timeout * Increase Request scheduler API tests timeout * Fix typo * Increase video transcoding API tests timeout * Move tests to Typescript * Use lodash orderBy method * Fix typos * Client: Remove optional tests in blacklist model attributes * Move blacklist routes from 'blacklists' to 'blacklist' * CLient: Remove blacklist-list.component.scss * Rename 'blacklists' files to 'blacklist' * Use only BlacklistedVideo interface * Server: Use getFormattedObjects method in listBlacklist method * Client: Use new coding style * Server: Use new sort validator methods * Server: Use new checkParams methods * Client: Fix sortable columns --- server/models/utils.ts | 10 +++++++++- server/models/video/video-blacklist-interface.ts | 6 +++++- server/models/video/video-blacklist.ts | 24 ++++++++++++++++++++---- 3 files changed, 34 insertions(+), 6 deletions(-) (limited to 'server/models') diff --git a/server/models/utils.ts b/server/models/utils.ts index 7ba96815e..1bf61d2a6 100644 --- a/server/models/utils.ts +++ b/server/models/utils.ts @@ -19,9 +19,17 @@ function addMethodsToModel (model: any, classMethods: Function[], instanceMethod instanceMethods.forEach(m => model.prototype[m.name] = m) } +function getSortOnModel (model: any, value: string) { + let sort = getSort(value) + + if (model) return [ { model: model }, sort[0], sort[1] ] + return sort +} + // --------------------------------------------------------------------------- export { addMethodsToModel, - getSort + getSort, + getSortOnModel } diff --git a/server/models/video/video-blacklist-interface.ts b/server/models/video/video-blacklist-interface.ts index ba48b1b6e..9d167c037 100644 --- a/server/models/video/video-blacklist-interface.ts +++ b/server/models/video/video-blacklist-interface.ts @@ -1,7 +1,9 @@ import * as Sequelize from 'sequelize' import * as Promise from 'bluebird' +import { SortType } from '../../helpers' import { ResultList } from '../../../shared' +import { VideoInstance } from './video-interface' // Don't use barrel, import just what we need import { BlacklistedVideo as FormattedBlacklistedVideo } from '../../../shared/models/videos/video-blacklist.model' @@ -13,7 +15,7 @@ export namespace BlacklistedVideoMethods { export type List = () => Promise - export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList > + export type ListForApi = (start: number, count: number, sort: SortType) => Promise< ResultList > export type LoadById = (id: number) => Promise @@ -31,6 +33,8 @@ export interface BlacklistedVideoClass { export interface BlacklistedVideoAttributes { videoId: number + + Video?: VideoInstance } export interface BlacklistedVideoInstance diff --git a/server/models/video/video-blacklist.ts b/server/models/video/video-blacklist.ts index dc49852b6..1c279b1ba 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, @@ -49,10 +51,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 } } @@ -76,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 }) => { -- cgit v1.2.3