From 951532924c1b3fd547cbf45f0c9cf9734203d6b4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 4 Sep 2019 16:23:37 +0200 Subject: [PATCH] Fix blacklist sort --- server/models/utils.ts | 10 +++++----- server/models/video/video-blacklist.ts | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/server/models/utils.ts b/server/models/utils.ts index 24890f961..e7e6ddde1 100644 --- a/server/models/utils.ts +++ b/server/models/utils.ts @@ -1,9 +1,9 @@ import { Model, Sequelize } from 'sequelize-typescript' import * as validator from 'validator' import { Col } from 'sequelize/types/lib/utils' -import { OrderItem, literal } from 'sequelize' +import { col, literal, OrderItem } from 'sequelize' -type SortType = { sortModel: any, sortValue: string } +type SortType = { sortModel: string, sortValue: string } // Translate for example "-name" to [ [ 'name', 'DESC' ], [ 'id', 'ASC' ] ] function getSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { @@ -51,10 +51,10 @@ function getVideoSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): Or return [ firstSort, lastSort ] } -function getSortOnModel (model: any, value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { +function getBlacklistSort (model: any, value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { const [ firstSort ] = getSort(value) - if (model) return [ [ model, firstSort[0], firstSort[1] ], lastSort ] + if (model) return [ [ literal(`"${model}.${firstSort[ 0 ]}" ${firstSort[ 1 ]}`) ], lastSort ] as any[] // FIXME: typings return [ firstSort, lastSort ] } @@ -155,7 +155,7 @@ export { buildLocalAccountIdsIn, getSort, getVideoSort, - getSortOnModel, + getBlacklistSort, createSimilarityAttribute, throwIfNotValid, buildServerIdsFollowedBy, diff --git a/server/models/video/video-blacklist.ts b/server/models/video/video-blacklist.ts index 18a1b8b4b..cdb725e7a 100644 --- a/server/models/video/video-blacklist.ts +++ b/server/models/video/video-blacklist.ts @@ -1,11 +1,11 @@ import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' -import { getSortOnModel, SortType, throwIfNotValid } from '../utils' +import { getBlacklistSort, getSort, SortType, throwIfNotValid } from '../utils' import { ScopeNames as VideoModelScopeNames, VideoModel } from './video' import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from './video-channel' import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../helpers/custom-validators/video-blacklist' import { VideoBlacklist, VideoBlacklistType } from '../../../shared/models/videos' import { CONSTRAINTS_FIELDS } from '../../initializers/constants' -import { FindOptions } from 'sequelize' +import { FindOptions, literal } from 'sequelize' import { ThumbnailModel } from './thumbnail' @Table({ @@ -57,7 +57,7 @@ export class VideoBlacklistModel extends Model { return { offset: start, limit: count, - order: getSortOnModel(sort.sortModel, sort.sortValue) + order: getBlacklistSort(sort.sortModel, sort.sortValue) } } -- 2.25.1