getAll: publicProcedure
.input(z.object({
limit: z.number(),
cursor: z.string().nullish(),
skip: z.number().optional(),
}))
.query(async ({ ctx, input }) => {
const { limit, skip, cursor } = input;
const posts = await ctx.prisma.post.findMany({
take: limit + 1,
skip: skip,
cursor: cursor ? { id: cursor } : undefined,
orderBy: {
createdAt: "desc"
},
});
let nextCursor: typeof cursor | undefined = undefined;
if (posts.length > limit) {
const nextItem = posts.pop();
nextCursor = nextItem?.id;
}
return {
posts,
nextCursor
};
}),
getAll: publicProcedure
.input(z.object({
limit: z.number(),
cursor: z.string().nullish(),
skip: z.number().optional(),
}))
.query(async ({ ctx, input }) => {
const { limit, skip, cursor } = input;
const posts = await ctx.prisma.post.findMany({
take: limit + 1,
skip: skip,
cursor: cursor ? { id: cursor } : undefined,
orderBy: {
createdAt: "desc"
},
});
let nextCursor: typeof cursor | undefined = undefined;
if (posts.length > limit) {
const nextItem = posts.pop();
nextCursor = nextItem?.id;
}
return {
posts,
nextCursor
};
}),