From a8738459318d40d1e16b6f9dfc34ac1f76e6b7e0 Mon Sep 17 00:00:00 2001 From: whtsupbab3 Date: Thu, 16 Jan 2025 17:53:10 -0800 Subject: [PATCH] fix: issue #475 --- src/trpc/routers/_app.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/trpc/routers/_app.ts b/src/trpc/routers/_app.ts index 67e5fa5..525c66f 100644 --- a/src/trpc/routers/_app.ts +++ b/src/trpc/routers/_app.ts @@ -210,7 +210,12 @@ export const appRouter = createTRPCRouter({ bountyId: z.number(), chainId: z.number(), limit: z.number().min(1).max(100).default(10), - cursor: z.number().nullish(), + cursor: z + .object({ + id: z.number(), + ids: z.array(z.number()), + }) + .nullish(), }) ) .query(async ({ input }) => { @@ -221,7 +226,8 @@ export const appRouter = createTRPCRouter({ ban: { none: {}, }, - ...(input.cursor ? { id: { lt: input.cursor } } : {}), + ...(input.cursor ? { id: { lt: input.cursor.id } } : {}), + ...(input.cursor && { id: { notIn: input.cursor.ids } }), }, orderBy: [{ is_accepted: 'desc' }, { id: 'desc' }], take: input.limit, @@ -236,9 +242,17 @@ export const appRouter = createTRPCRouter({ }, }); - let nextCursor: (typeof items)[number]['id'] | undefined = undefined; + let nextCursor: + | { + id: (typeof items)[number]['id']; + ids: (typeof items)[number]['id'][]; + } + | undefined = undefined; if (items.length === input.limit) { - nextCursor = items[items.length - 1].id; + nextCursor = { + id: items[items.length - 1].id, + ids: [...(input.cursor?.ids ?? []), ...items.map((item) => item.id)], + }; } return {