MCPcopy Create free account
hub / github.com/Hazrat-Ali9/Problem-Solving-Frontend / likeOnComment

Function likeOnComment

lib/firebase/comment.ts:80–104  ·  view source on GitHub ↗
(commentId: string, userId: string)

Source from the content-addressed store, hash-verified

78 }
79};
80export const likeOnComment = async (commentId: string, userId: string) => {
81 try {
82 const commentRef = doc(db, COMMENTS, commentId);
83 const comment = await getSingleComment(commentId);
84 if (!comment) {
85 throw new Error("Comment not found");
86 }
87 if (comment.likes.includes(userId)) {
88 const likes = comment.likes.filter((id: string) => id !== userId);
89 await updateDoc(commentRef, {
90 likes,
91 });
92 return;
93 } else {
94 const likes = [...comment.likes, userId];
95 await updateDoc(commentRef, {
96 likes,
97 });
98 }
99 return comment;
100 } catch (error) {
101 console.error("Error liking comment:", error);
102 throw error;
103 }
104};
105
106export const replyComment = async (commentId: string, data: any) => {
107 try {

Callers 1

likeCommentFunction · 0.90

Calls 1

getSingleCommentFunction · 0.85

Tested by

no test coverage detected