Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 2x 2x 1x 1x | import {CommentModel } from '../models/comments_model';
import { IComment, CommentData } from '../types/comment_types';
export const addComment = async (commentData: CommentData): Promise<IComment> => {
const comment = new CommentModel(commentData);
return await comment.save();
};
export const getCommentsWithAuthorsByPostId = async (postId: string): Promise<IComment[]> => {
return await CommentModel.find({ postId })
.populate('author', 'username email') // Fetch user details for the comment author
.exec();
};
export const getCommentsByPostId = async (postId: string): Promise<IComment[]> => {
return await CommentModel.find({ postId }).exec();
};
export const getAllComments = async (): Promise<IComment[]> => {
return await CommentModel.find().exec();
};
export const updateComment = async (commentId: string, commentData: Partial<CommentData>): Promise<IComment | null> => {
return await CommentModel.findByIdAndUpdate(commentId, commentData, { new: true }).exec();
};
export const deleteComment = async (commentId: string): Promise<IComment | null> => {
return await CommentModel.findByIdAndDelete(commentId).exec();
};
export const getCommentById = async (commentId: string): Promise<IComment | null> => {
return await CommentModel.findById(commentId).exec();
}; |