aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/utils.ts13
1 files changed, 8 insertions, 5 deletions
diff --git a/server/models/utils.ts b/server/models/utils.ts
index edb8e1161..e0bf091ad 100644
--- a/server/models/utils.ts
+++ b/server/models/utils.ts
@@ -4,7 +4,11 @@ type SortType = { sortModel: any, sortValue: string }
4 4
5// Translate for example "-name" to [ [ 'name', 'DESC' ], [ 'id', 'ASC' ] ] 5// Translate for example "-name" to [ [ 'name', 'DESC' ], [ 'id', 'ASC' ] ]
6function getSort (value: string, lastSort: string[] = [ 'id', 'ASC' ]) { 6function getSort (value: string, lastSort: string[] = [ 'id', 'ASC' ]) {
7 const { direction, field } = buildDirectionAndField(value) 7 let { direction, field } = buildDirectionAndField(value)
8
9 if (field.toLowerCase() === 'match') { // Search
10 field = Sequelize.col('similarity')
11 }
8 12
9 return [ [ field, direction ], lastSort ] 13 return [ [ field, direction ], lastSort ]
10} 14}
@@ -13,10 +17,9 @@ function getVideoSort (value: string, lastSort: string[] = [ 'id', 'ASC' ]) {
13 let { direction, field } = buildDirectionAndField(value) 17 let { direction, field } = buildDirectionAndField(value)
14 18
15 // Alias 19 // Alias
16 if (field.toLowerCase() === 'match') field = Sequelize.col('similarity') 20 if (field.toLowerCase() === 'match') { // Search
17 21 field = Sequelize.col('similarity')
18 // Sort by aggregation 22 } else if (field.toLowerCase() === 'trending') { // Sort by aggregation
19 if (field.toLowerCase() === 'trending') {
20 return [ 23 return [
21 [ Sequelize.fn('COALESCE', Sequelize.fn('SUM', Sequelize.col('VideoViews.views')), '0'), direction ], 24 [ Sequelize.fn('COALESCE', Sequelize.fn('SUM', Sequelize.col('VideoViews.views')), '0'), direction ],
22 25