From c1125bcadc1fa129856e56dc62f4c472cffa736a Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Fri, 27 Dec 2019 17:02:34 +0100 Subject: Add comment filtering by reply count --- server/models/utils.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'server/models/utils.ts') diff --git a/server/models/utils.ts b/server/models/utils.ts index b53a52a05..4199cc443 100644 --- a/server/models/utils.ts +++ b/server/models/utils.ts @@ -22,6 +22,19 @@ function getSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderIt return [ [ finalField, direction ], lastSort ] } +function getCommentSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { + const { direction, field } = buildDirectionAndField(value) + + if (field === 'totalReplies') { + return [ + [ Sequelize.literal('"totalReplies"'), direction ], + lastSort + ] + } + + return getSort(value, lastSort) +} + function getVideoSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { const { direction, field } = buildDirectionAndField(value) @@ -167,6 +180,7 @@ export { SortType, buildLocalAccountIdsIn, getSort, + getCommentSort, getVideoSort, getBlacklistSort, createSimilarityAttribute, -- cgit v1.2.3