Fakultas Ilmu Komputer UI

Commit 611fb411 authored by Abraham Rudolf Brahmana's avatar Abraham Rudolf Brahmana Committed by Ahmad Izzudin Alifyandra
Browse files

feat: Forum fetch function

parent 1ea53e4b
import firebase from "firebase";
import { getEnv } from "../../../helpers/getEnv";
import { IThreadComment } from "../../../types/firestore/threadComment";
export const fetchCommentsByPostId = async (
postId: string
): Promise<IThreadComment[]> => {
const db = firebase.firestore();
const query = db
.collection("thread_comments_" + getEnv())
.where("threadId", "==", postId)
.orderBy("timestamp", "desc");
const snap = await query.get();
const comments: IThreadComment[] = [];
snap.docs.forEach((doc) => {
const data: IThreadComment = {
...(doc.data() as IThreadComment),
id: doc.id,
};
comments.push(data);
});
return comments;
};
import firebase from "firebase";
import { getEnv } from "../../../helpers/getEnv";
import { IThread } from "../../../types/firestore/thread";
export const fetchPost = async (postId: string) => {
const db = firebase.firestore();
const query = db.collection("threads_" + getEnv()).doc(postId);
const snap = await query.get();
const post = { ...(snap.data() as IThread), id: snap.id };
return post;
};
import firebase from "firebase";
import { getEnv } from "../../../helpers/getEnv";
import { IThread } from "../../../types/firestore/thread";
export const fetchPostsByEcosystemId = async (
ecosystemId: string
): Promise<IThread[]> => {
const db = firebase.firestore();
const query = db
.collection("threads_" + getEnv())
.where("ecosystemId", "==", ecosystemId)
.orderBy("timestamp", "desc");
const snap = await query.get();
const posts: IThread[] = [];
snap.docs.forEach((doc) => {
const data: IThread = { ...(doc.data() as IThread), id: doc.id };
posts.push(data);
});
return posts;
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment