From 071071663e89c719184b548ebddb9c095a49d8cc Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Wed, 15 Feb 2023 10:31:10 -0800 Subject: [PATCH] fix: :bug: pagination for "/api/channels/followed" Co-authored-by: takonomura <@takonomura@github.com> --- .../server/api/endpoints/channels/followed.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/channels/followed.ts b/packages/backend/src/server/api/endpoints/channels/followed.ts index 63483a79a..f9e61222f 100644 --- a/packages/backend/src/server/api/endpoints/channels/followed.ts +++ b/packages/backend/src/server/api/endpoints/channels/followed.ts @@ -1,6 +1,5 @@ import define from "../../define.js"; import { Channels, ChannelFollowings } from "@/models/index.js"; -import { makePaginationQuery } from "../../common/make-pagination-query.js"; export const meta = { tags: ["channels", "account"], @@ -33,11 +32,18 @@ export const paramDef = { } as const; export default define(meta, paramDef, async (ps, me) => { - const query = makePaginationQuery( - ChannelFollowings.createQueryBuilder(), - ps.sinceId, - ps.untilId, - ).andWhere({ followerId: me.id }); + const query = ChannelFollowings.createQueryBuilder('following').andWhere({ followerId: me.id }); + if (ps.sinceId) { + query.andWhere('following."followeeId" > :sinceId', { sinceId: ps.sinceId }); + } + if (ps.untilId) { + query.andWhere('following."followeeId" < :untilId', { untilId: ps.untilId }); + } + if (ps.sinceId && !ps.untilId) { + query.orderBy('following."followeeId"', 'ASC'); + } else { + query.orderBy('following."followeeId"', 'DESC'); + } const followings = await query.take(ps.limit).getMany();