| 41 | } |
| 42 | |
| 43 | export async function getCommentByPostId(postId: string): Promise<any> { |
| 44 | try { |
| 45 | const commentRef = collection(db, COMMENTS); |
| 46 | const q = query(commentRef, where("pid", "==", postId)); |
| 47 | const querySnapshot = await getDocs(q); |
| 48 | |
| 49 | if (querySnapshot.empty) { |
| 50 | throw new Error("No comments found for this post."); |
| 51 | } |
| 52 | |
| 53 | const comments = querySnapshot.docs.map((doc) => ({ |
| 54 | id: doc.id, |
| 55 | ...doc.data(), |
| 56 | })); |
| 57 | return comments; |
| 58 | } catch (error) { |
| 59 | console.error("Error fetching comments:", error); |
| 60 | throw error; |
| 61 | } |
| 62 | } |
| 63 | const getSingleComment = async (commentId: string): Promise<any> => { |
| 64 | try { |
| 65 | const docRef = doc(db, COMMENTS, commentId); |