mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-18 03:01:09 +01:00
🐛 Fix paging on manage user invites
This commit is contained in:
@@ -8,24 +8,17 @@ export const inviteRouter = createTRPCRouter({
|
||||
getAllInvites: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
limit: z.number().min(1).max(100).nullish(),
|
||||
cursor: z.string().nullish(),
|
||||
limit: z.number().min(1).max(100).nullish().default(10),
|
||||
page: z.number().min(0)
|
||||
})
|
||||
)
|
||||
.query(async ({ ctx, input }) => {
|
||||
const limit = input.limit ?? 50;
|
||||
const cursor = input.cursor;
|
||||
const registrationTokens = await ctx.prisma.registrationToken.findMany({
|
||||
take: limit + 1, // get an extra item at the end which we'll use as next cursor
|
||||
cursor: cursor ? { id: cursor } : undefined,
|
||||
take: limit,
|
||||
skip: limit * input.page,
|
||||
});
|
||||
|
||||
let nextCursor: typeof cursor | undefined = undefined;
|
||||
if (registrationTokens.length > limit) {
|
||||
const nextItem = registrationTokens.pop();
|
||||
nextCursor = nextItem!.id;
|
||||
}
|
||||
|
||||
const countRegistrationTokens = await ctx.prisma.registrationToken.count();
|
||||
|
||||
return {
|
||||
@@ -33,7 +26,6 @@ export const inviteRouter = createTRPCRouter({
|
||||
id: token.id,
|
||||
expires: token.expires,
|
||||
})),
|
||||
nextCursor,
|
||||
countPages: Math.ceil(countRegistrationTokens / limit)
|
||||
};
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user