(commentId: string, userId: string)
| 78 | } |
| 79 | }; |
| 80 | export 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 | |
| 106 | export const replyComment = async (commentId: string, data: any) => { |
| 107 | try { |
no test coverage detected