aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-09-04 16:23:37 +0200
committerChocobozzz <me@florianbigard.com>2019-09-04 16:23:37 +0200
commit951532924c1b3fd547cbf45f0c9cf9734203d6b4 (patch)
tree1fa1ef653a9591932a057ea1317a2ea129b96665 /server
parent5eb9bde8aa50951c7896d5278d0788dda541c475 (diff)
downloadPeerTube-951532924c1b3fd547cbf45f0c9cf9734203d6b4.tar.gz
PeerTube-951532924c1b3fd547cbf45f0c9cf9734203d6b4.tar.zst
PeerTube-951532924c1b3fd547cbf45f0c9cf9734203d6b4.zip
Fix blacklist sort
Diffstat (limited to 'server')
-rw-r--r--server/models/utils.ts10
-rw-r--r--server/models/video/video-blacklist.ts6
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 @@
1import { Model, Sequelize } from 'sequelize-typescript' 1import { Model, Sequelize } from 'sequelize-typescript'
2import * as validator from 'validator' 2import * as validator from 'validator'
3import { Col } from 'sequelize/types/lib/utils' 3import { Col } from 'sequelize/types/lib/utils'
4import { OrderItem, literal } from 'sequelize' 4import { col, literal, OrderItem } from 'sequelize'
5 5
6type SortType = { sortModel: any, sortValue: string } 6type SortType = { sortModel: string, sortValue: string }
7 7
8// Translate for example "-name" to [ [ 'name', 'DESC' ], [ 'id', 'ASC' ] ] 8// Translate for example "-name" to [ [ 'name', 'DESC' ], [ 'id', 'ASC' ] ]
9function getSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { 9function getSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
@@ -51,10 +51,10 @@ function getVideoSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): Or
51 return [ firstSort, lastSort ] 51 return [ firstSort, lastSort ]
52} 52}
53 53
54function getSortOnModel (model: any, value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { 54function getBlacklistSort (model: any, value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
55 const [ firstSort ] = getSort(value) 55 const [ firstSort ] = getSort(value)
56 56
57 if (model) return [ [ model, firstSort[0], firstSort[1] ], lastSort ] 57 if (model) return [ [ literal(`"${model}.${firstSort[ 0 ]}" ${firstSort[ 1 ]}`) ], lastSort ] as any[] // FIXME: typings
58 return [ firstSort, lastSort ] 58 return [ firstSort, lastSort ]
59} 59}
60 60
@@ -155,7 +155,7 @@ export {
155 buildLocalAccountIdsIn, 155 buildLocalAccountIdsIn,
156 getSort, 156 getSort,
157 getVideoSort, 157 getVideoSort,
158 getSortOnModel, 158 getBlacklistSort,
159 createSimilarityAttribute, 159 createSimilarityAttribute,
160 throwIfNotValid, 160 throwIfNotValid,
161 buildServerIdsFollowedBy, 161 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 @@
1import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' 1import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
2import { getSortOnModel, SortType, throwIfNotValid } from '../utils' 2import { getBlacklistSort, getSort, SortType, throwIfNotValid } from '../utils'
3import { ScopeNames as VideoModelScopeNames, VideoModel } from './video' 3import { ScopeNames as VideoModelScopeNames, VideoModel } from './video'
4import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from './video-channel' 4import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from './video-channel'
5import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../helpers/custom-validators/video-blacklist' 5import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../helpers/custom-validators/video-blacklist'
6import { VideoBlacklist, VideoBlacklistType } from '../../../shared/models/videos' 6import { VideoBlacklist, VideoBlacklistType } from '../../../shared/models/videos'
7import { CONSTRAINTS_FIELDS } from '../../initializers/constants' 7import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
8import { FindOptions } from 'sequelize' 8import { FindOptions, literal } from 'sequelize'
9import { ThumbnailModel } from './thumbnail' 9import { ThumbnailModel } from './thumbnail'
10 10
11@Table({ 11@Table({
@@ -57,7 +57,7 @@ export class VideoBlacklistModel extends Model<VideoBlacklistModel> {
57 return { 57 return {
58 offset: start, 58 offset: start,
59 limit: count, 59 limit: count,
60 order: getSortOnModel(sort.sortModel, sort.sortValue) 60 order: getBlacklistSort(sort.sortModel, sort.sortValue)
61 } 61 }
62 } 62 }
63 63