diff options
author | Chocobozzz <me@florianbigard.com> | 2018-02-19 09:41:03 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-02-19 10:48:44 +0100 |
commit | 3bb6c52645af84832212c99fdec04143e4230180 (patch) | |
tree | d91539e2aed89bdd0e6d0530db5e92da45e20fb9 /server/models/utils.ts | |
parent | 2519d9fec6f84906d1b10770be791ad367186ca7 (diff) | |
download | PeerTube-3bb6c52645af84832212c99fdec04143e4230180.tar.gz PeerTube-3bb6c52645af84832212c99fdec04143e4230180.tar.zst PeerTube-3bb6c52645af84832212c99fdec04143e4230180.zip |
Fix sort inconsistency
Diffstat (limited to 'server/models/utils.ts')
-rw-r--r-- | server/models/utils.ts | 14 |
1 files changed, 7 insertions, 7 deletions
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' ] ] |
2 | function getSort (value: string) { | 2 | function 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 | ||
17 | function getSortOnModel (model: any, value: string) { | 17 | function 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 | ||
24 | function throwIfNotValid (value: any, validator: (value: any) => boolean, fieldName = 'value') { | 24 | function throwIfNotValid (value: any, validator: (value: any) => boolean, fieldName = 'value') { |