Fakultas Ilmu Komputer UI

categories.ts 545 Bytes
Newer Older
1
import firebase from "firebase";
2
import { ICategory } from "../../types/firestore";
3
4
5
6
7
8
9
10

export const getCategories = async (): Promise<ICategory[]> => {
  const db = firebase.firestore();
  // We dont need to do a .where() method since we just want to get all the documents in the collection
  const snap = await db.collection("categories").get();
  const categories: ICategory[] = [];
  snap.docs.forEach((doc) => {
    const data: ICategory = { ...(doc.data() as ICategory), id: doc.id };
11
    categories.push(data);
12
13
14
  });
  return categories;
};