const result = await prisma.post.findMany({
where: { user: { username: { equals: username, mode: "insensitive" } } },
include: getPostInclude(user.id),
orderBy: { createdAt: "desc" },
take: pageSize + 1,
cursor: cursor ? { id: cursor } : undefined,
});
const posts = result.slice(0, pageSize); // Posts are in desc order
const postIds = posts.map((post) => post.id);
const postTransactions = postIds.map((postId) => {
return prisma.$queryRawTyped(getPostReactions(postId, user.id));
});
const postReactions = await prisma.$transaction(postTransactions); // Here is that query you provided! :)
const postsWithReactions = posts.map((post, index) => ({
data: post,
reactions: postReactions[index] as TPostReactions[],
}));
const nextCursor = posts.length > pageSize ? posts[pageSize].id : null;
const data: TProfilePostsPage = {
posts: postsWithReactions,
nextCursor,
};
const result = await prisma.post.findMany({
where: { user: { username: { equals: username, mode: "insensitive" } } },
include: getPostInclude(user.id),
orderBy: { createdAt: "desc" },
take: pageSize + 1,
cursor: cursor ? { id: cursor } : undefined,
});
const posts = result.slice(0, pageSize); // Posts are in desc order
const postIds = posts.map((post) => post.id);
const postTransactions = postIds.map((postId) => {
return prisma.$queryRawTyped(getPostReactions(postId, user.id));
});
const postReactions = await prisma.$transaction(postTransactions); // Here is that query you provided! :)
const postsWithReactions = posts.map((post, index) => ({
data: post,
reactions: postReactions[index] as TPostReactions[],
}));
const nextCursor = posts.length > pageSize ? posts[pageSize].id : null;
const data: TProfilePostsPage = {
posts: postsWithReactions,
nextCursor,
};