X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Futils.ts;h=b53a52a053f9e86276a2632a3185ef2665044832;hb=611a72ae15ff0cd67e5abba215c8f8566652eb98;hp=e7e6ddde1f61e6c86117b4fa073f32bf6ebfe45e;hpb=00aab0666c6f772548c160fdfa871a8843b88f37;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/utils.ts b/server/models/utils.ts index e7e6ddde1..b53a52a05 100644 --- a/server/models/utils.ts +++ b/server/models/utils.ts @@ -1,7 +1,7 @@ import { Model, Sequelize } from 'sequelize-typescript' import * as validator from 'validator' import { Col } from 'sequelize/types/lib/utils' -import { col, literal, OrderItem } from 'sequelize' +import { literal, OrderItem } from 'sequelize' type SortType = { sortModel: string, sortValue: string } @@ -58,6 +58,19 @@ function getBlacklistSort (model: any, value: string, lastSort: OrderItem = [ 'i return [ firstSort, lastSort ] } +function getFollowsSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { + const { direction, field } = buildDirectionAndField(value) + + if (field === 'redundancyAllowed') { + return [ + [ 'ActorFollowing', 'Server', 'redundancyAllowed', direction ], + lastSort + ] + } + + return getSort(value, lastSort) +} + function isOutdated (model: { createdAt: Date, updatedAt: Date }, refreshInterval: number) { const now = Date.now() const createdAtTime = model.createdAt.getTime() @@ -163,6 +176,7 @@ export { buildWhereIdOrUUID, isOutdated, parseAggregateResult, + getFollowsSort, createSafeIn }