aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/utils.ts')
-rw-r--r--server/models/utils.ts14
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' ] ]
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') {