MCPcopy Create free account
hub / github.com/code100x/cms / getComments

Function getComments

src/actions/comment/index.ts:30–72  ·  view source on GitHub ↗
(
  q: Prisma.CommentFindManyArgs,
  parentId: number | null | undefined,
)

Source from the content-addressed store, hash-verified

28import { ROLES } from '../types';
29
30export const getComments = async (
31 q: Prisma.CommentFindManyArgs,
32 parentId: number | null | undefined,
33) => {
34 let parentComment = null;
35 if (parentId) {
36 parentComment = await prisma.comment.findUnique({
37 where: { id: parseInt(parentId.toString(), 10) },
38 include: {
39 user: true,
40 },
41 });
42 }
43 if (!parentComment) {
44 delete q.where?.parentId;
45 }
46 const pinnedComment = await prisma.comment.findFirst({
47 where: {
48 contentId: q.where?.contentId,
49 isPinned: true,
50 ...(parentId ? { parentId: parseInt(parentId.toString(), 10) } : {}),
51 },
52 include: q.include,
53 });
54 if (pinnedComment) {
55 q.where = {
56 ...q.where,
57 NOT: {
58 id: pinnedComment.id,
59 },
60 };
61 }
62
63 const comments = await prisma.comment.findMany(q);
64 const combinedComments = pinnedComment
65 ? [pinnedComment, ...comments]
66 : comments;
67
68 return {
69 comments: combinedComments,
70 parentComment,
71 };
72};
73const parseIntroComment = (comment: string) => {
74 const introPattern = /^intro:\s*([\s\S]*)$/i;
75 const match = comment.match(introPattern);

Callers 1

CommentsFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected