aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-02-19 09:41:03 +0100
committerChocobozzz <me@florianbigard.com>2018-02-19 10:48:44 +0100
commit3bb6c52645af84832212c99fdec04143e4230180 (patch)
treed91539e2aed89bdd0e6d0530db5e92da45e20fb9 /server
parent2519d9fec6f84906d1b10770be791ad367186ca7 (diff)
downloadPeerTube-3bb6c52645af84832212c99fdec04143e4230180.tar.gz
PeerTube-3bb6c52645af84832212c99fdec04143e4230180.tar.zst
PeerTube-3bb6c52645af84832212c99fdec04143e4230180.zip
Fix sort inconsistency
Diffstat (limited to 'server')
-rw-r--r--server/models/account/account.ts2
-rw-r--r--server/models/account/user.ts2
-rw-r--r--server/models/activitypub/actor-follow.ts4
-rw-r--r--server/models/utils.ts14
-rw-r--r--server/models/video/video-abuse.ts2
-rw-r--r--server/models/video/video-blacklist.ts2
-rw-r--r--server/models/video/video-channel.ts4
-rw-r--r--server/models/video/video-comment.ts2
-rw-r--r--server/models/video/video.ts8
9 files changed, 20 insertions, 20 deletions
diff --git a/server/models/account/account.ts b/server/models/account/account.ts
index d8f305c37..54ec7cfcc 100644
--- a/server/models/account/account.ts
+++ b/server/models/account/account.ts
@@ -197,7 +197,7 @@ export class AccountModel extends Model<AccountModel> {
197 const query = { 197 const query = {
198 offset: start, 198 offset: start,
199 limit: count, 199 limit: count,
200 order: [ getSort(sort) ] 200 order: getSort(sort),
201 } 201 }
202 202
203 return AccountModel.findAndCountAll(query) 203 return AccountModel.findAndCountAll(query)
diff --git a/server/models/account/user.ts b/server/models/account/user.ts
index 653921907..292a5d150 100644
--- a/server/models/account/user.ts
+++ b/server/models/account/user.ts
@@ -125,7 +125,7 @@ export class UserModel extends Model<UserModel> {
125 const query = { 125 const query = {
126 offset: start, 126 offset: start,
127 limit: count, 127 limit: count,
128 order: [ getSort(sort) ] 128 order: getSort(sort),
129 } 129 }
130 130
131 return UserModel.findAndCountAll(query) 131 return UserModel.findAndCountAll(query)
diff --git a/server/models/activitypub/actor-follow.ts b/server/models/activitypub/actor-follow.ts
index a32f5f498..8260904a1 100644
--- a/server/models/activitypub/actor-follow.ts
+++ b/server/models/activitypub/actor-follow.ts
@@ -215,7 +215,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
215 distinct: true, 215 distinct: true,
216 offset: start, 216 offset: start,
217 limit: count, 217 limit: count,
218 order: [ getSort(sort) ], 218 order: getSort(sort),
219 include: [ 219 include: [
220 { 220 {
221 model: ActorModel, 221 model: ActorModel,
@@ -248,7 +248,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
248 distinct: true, 248 distinct: true,
249 offset: start, 249 offset: start,
250 limit: count, 250 limit: count,
251 order: [ getSort(sort) ], 251 order: getSort(sort),
252 include: [ 252 include: [
253 { 253 {
254 model: ActorModel, 254 model: ActorModel,
diff --git a/server/models/utils.ts b/server/models/utils.ts
index 1606453e0..59ce83c16 100644
--- a/server/models/utils.ts
+++ b/server/models/utils.ts
@@ -1,5 +1,5 @@
1// Translate for example "-name" to [ 'name', 'DESC' ] 1// Translate for example "-name" to [ [ 'name', 'DESC' ], [ 'id', 'ASC' ] ]
2function getSort (value: string) { 2function getSort (value: string, lastSort: string[] = [ 'id', 'ASC' ]) {
3 let field: string 3 let field: string
4 let direction: 'ASC' | 'DESC' 4 let direction: 'ASC' | 'DESC'
5 5
@@ -11,14 +11,14 @@ function getSort (value: string) {
11 field = value 11 field = value
12 } 12 }
13 13
14 return [ field, direction ] 14 return [ [ field, direction ], lastSort ]
15} 15}
16 16
17function getSortOnModel (model: any, value: string) { 17function getSortOnModel (model: any, value: string, lastSort: string[] = [ 'id', 'ASC' ]) {
18 let sort = getSort(value) 18 let [ firstSort ] = getSort(value)
19 19
20 if (model) return [ model, sort[0], sort[1] ] 20 if (model) return [ [ model, firstSort[0], firstSort[1] ], lastSort ]
21 return sort 21 return [ firstSort, lastSort ]
22} 22}
23 23
24function throwIfNotValid (value: any, validator: (value: any) => boolean, fieldName = 'value') { 24function throwIfNotValid (value: any, validator: (value: any) => boolean, fieldName = 'value') {
diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts
index cc7078ae7..65b734442 100644
--- a/server/models/video/video-abuse.ts
+++ b/server/models/video/video-abuse.ts
@@ -64,7 +64,7 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
64 const query = { 64 const query = {
65 offset: start, 65 offset: start,
66 limit: count, 66 limit: count,
67 order: [ getSort(sort) ], 67 order: getSort(sort),
68 include: [ 68 include: [
69 { 69 {
70 model: AccountModel, 70 model: AccountModel,
diff --git a/server/models/video/video-blacklist.ts b/server/models/video/video-blacklist.ts
index 3adcec149..26167174a 100644
--- a/server/models/video/video-blacklist.ts
+++ b/server/models/video/video-blacklist.ts
@@ -36,7 +36,7 @@ export class VideoBlacklistModel extends Model<VideoBlacklistModel> {
36 const query = { 36 const query = {
37 offset: start, 37 offset: start,
38 limit: count, 38 limit: count,
39 order: [ getSortOnModel(sort.sortModel, sort.sortValue) ], 39 order: getSortOnModel(sort.sortModel, sort.sortValue),
40 include: [ { model: VideoModel } ] 40 include: [ { model: VideoModel } ]
41 } 41 }
42 42
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts
index 289775a0f..40f3be7fe 100644
--- a/server/models/video/video-channel.ts
+++ b/server/models/video/video-channel.ts
@@ -151,7 +151,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
151 const query = { 151 const query = {
152 offset: start, 152 offset: start,
153 limit: count, 153 limit: count,
154 order: [ getSort(sort) ] 154 order: getSort(sort)
155 } 155 }
156 156
157 return VideoChannelModel 157 return VideoChannelModel
@@ -164,7 +164,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
164 164
165 static listByAccount (accountId: number) { 165 static listByAccount (accountId: number) {
166 const query = { 166 const query = {
167 order: [ getSort('createdAt') ], 167 order: getSort('createdAt'),
168 include: [ 168 include: [
169 { 169 {
170 model: AccountModel, 170 model: AccountModel,
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts
index ab0f05d6e..47e3211a3 100644
--- a/server/models/video/video-comment.ts
+++ b/server/models/video/video-comment.ts
@@ -268,7 +268,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
268 const query = { 268 const query = {
269 offset: start, 269 offset: start,
270 limit: count, 270 limit: count,
271 order: [ getSort(sort) ], 271 order: getSort(sort),
272 where: { 272 where: {
273 videoId, 273 videoId,
274 inReplyToCommentId: null 274 inReplyToCommentId: null
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index aa1878caa..59a39b1a9 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -493,7 +493,7 @@ export class VideoModel extends Model<VideoModel> {
493 distinct: true, 493 distinct: true,
494 offset: start, 494 offset: start,
495 limit: count, 495 limit: count,
496 order: [ getSort('createdAt'), [ 'Tags', 'name', 'ASC' ] ], 496 order: getSort('createdAt', [ 'Tags', 'name', 'ASC' ]),
497 where: { 497 where: {
498 id: { 498 id: {
499 [Sequelize.Op.in]: Sequelize.literal('(' + rawQuery + ')') 499 [Sequelize.Op.in]: Sequelize.literal('(' + rawQuery + ')')
@@ -607,7 +607,7 @@ export class VideoModel extends Model<VideoModel> {
607 const query = { 607 const query = {
608 offset: start, 608 offset: start,
609 limit: count, 609 limit: count,
610 order: [ getSort(sort) ], 610 order: getSort(sort),
611 include: [ 611 include: [
612 { 612 {
613 model: VideoChannelModel, 613 model: VideoChannelModel,
@@ -637,7 +637,7 @@ export class VideoModel extends Model<VideoModel> {
637 const query = { 637 const query = {
638 offset: start, 638 offset: start,
639 limit: count, 639 limit: count,
640 order: [ getSort(sort) ] 640 order: getSort(sort),
641 } 641 }
642 642
643 const serverActor = await getServerActor() 643 const serverActor = await getServerActor()
@@ -656,7 +656,7 @@ export class VideoModel extends Model<VideoModel> {
656 const query: IFindOptions<VideoModel> = { 656 const query: IFindOptions<VideoModel> = {
657 offset: start, 657 offset: start,
658 limit: count, 658 limit: count,
659 order: [ getSort(sort) ], 659 order: getSort(sort),
660 where: { 660 where: {
661 name: { 661 name: {
662 [Sequelize.Op.iLike]: '%' + value + '%' 662 [Sequelize.Op.iLike]: '%' + value + '%'