Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/app/api/comment/comment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,10 @@ export class CommentService extends BaseService {
return comment
}

async getCommentById(id: string) {
async getCommentById({ id, includeAttachments }: { id: string; includeAttachments?: boolean }) {
const comment = await this.db.comment.findFirst({
where: { id, deletedAt: undefined }, // Can also get soft deleted comments
include: { attachments: includeAttachments },
})
if (!comment) return null

Expand Down
4 changes: 4 additions & 0 deletions src/app/api/comment/public/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { getOneCommentPublicForTask } from '@/app/api/comment/public/comment-public.controller'
import { withErrorHandler } from '@/app/api/core/utils/withErrorHandler'

export const GET = withErrorHandler(getOneCommentPublicForTask)
12 changes: 12 additions & 0 deletions src/app/api/comment/public/comment-public.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,15 @@ export const getAllCommentsPublicForTask = async (req: NextRequest, { params }:
nextToken: base64NextToken,
})
}

export const getOneCommentPublicForTask = async (req: NextRequest, { params }: IdParams) => {
const { id } = await params
const user = await authenticate(req)

const commentService = new CommentService(user)
const comment = await commentService.getCommentById({ id, includeAttachments: true })

if (!comment) return NextResponse.json({ data: null })

return NextResponse.json({ data: await PublicCommentSerializer.serialize(comment) })
}
2 changes: 1 addition & 1 deletion src/jobs/notifications/send-reply-create-notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const sendReplyCreateNotifications = task({
}

const commentService = new CommentService(user)
const parentComment = await commentService.getCommentById(comment.parentId)
const parentComment = await commentService.getCommentById({ id: comment.parentId })
if (parentComment) {
// Queue notification for parent comment initiator, if:
// - Parent Comment hasn't been deleted yet
Expand Down
Loading