Skip to main content

fetchComments

Retrieves all comments for a specific post, sorted by creation date (newest first).
postId
string
required
ID of the post to fetch comments for
Returns: Promise<{ rows: CommentType[], total: number }> Error Handling: Throws error if fetching fails. Error is logged and re-thrown.
import { fetchComments } from '@/services/comments.service';

const data = await fetchComments('post123');
const comments = data.rows;

// Display comments
comments.forEach(comment => {
  console.log(`${comment.authorName}: ${comment.content}`);
});

executeComment

Executes a comment action through the comments guard function. This is the recommended way to perform comment operations as it includes proper validation and authorization.
action
'add' | 'update' | 'delete'
required
The action to perform on the comment
postId
string
ID of the post (required for add action)
commentId
string
ID of the comment (required for update and delete actions)
content
string
Comment content (required for add and update actions)
Returns: Promise<Execution> Error Handling: Throws error if execution fails or status is “failed”. Error is logged and re-thrown.
import { executeComment } from '@/services/comments.service';

// Add a comment
await executeComment({
  action: 'add',
  postId: 'post123',
  content: 'Great analysis!'
});

// Update a comment
await executeComment({
  action: 'update',
  commentId: 'comment123',
  content: 'Updated comment text'
});

// Delete a comment
await executeComment({
  action: 'delete',
  commentId: 'comment123'
});

Build docs developers (and LLMs) love