Browse Source

feat(posts): add comment context resolvers for public and unlisted

Made-with: Cursor
main
npmrun 4 hours ago
parent
commit
c218105c25
  1. 50
      server/service/posts/index.ts

50
server/service/posts/index.ts

@ -166,6 +166,56 @@ export async function getPublicPostByPublicSlugAndSlug(publicSlug: string, postS
return row ?? null;
}
export async function getPublicPostCommentContext(
publicSlug: string,
postSlug: string,
): Promise<{ id: number; userId: number } | null> {
const slug = postSlug.trim();
if (!slug) {
return null;
}
const [row] = await dbGlobal
.select({
id: posts.id,
userId: posts.userId,
})
.from(posts)
.innerJoin(users, eq(posts.userId, users.id))
.where(
and(
eq(users.publicSlug, publicSlug),
eq(users.status, "active"),
eq(posts.visibility, "public"),
eq(posts.slug, slug),
),
)
.limit(1);
return row ?? null;
}
export async function getUnlistedPostCommentContext(
publicSlug: string,
shareToken: string,
): Promise<{ id: number; userId: number } | null> {
const [row] = await dbGlobal
.select({
id: posts.id,
userId: posts.userId,
})
.from(posts)
.innerJoin(users, eq(posts.userId, users.id))
.where(
and(
eq(users.publicSlug, publicSlug),
eq(users.status, "active"),
eq(posts.visibility, "unlisted"),
eq(posts.shareToken, shareToken),
),
)
.limit(1);
return row ?? null;
}
export async function getUnlistedPost(publicSlug: string, shareToken: string) {
const [row] = await dbGlobal
.select({ post: posts })

Loading…
Cancel
Save