-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathFetchAllToDoItems.js
More file actions
22 lines (17 loc) · 975 Bytes
/
FetchAllToDoItems.js
File metadata and controls
22 lines (17 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { db } from "../../firebaseConfig.js";
import { collection, getDocs } from "https://www.gstatic.com/firebasejs/10.5.2/firebase-firestore.js";
export async function fetchAllToDoItems(userId) {
try {
/*STEP 8: Get a refernce to the collection we want to store. Lets use the following documentation
to figure this out: https://firebase.google.com/docs/firestore/query-data/get-data */
const userTodoListCollection = collection(db, `todo-list-${userId}`);
// get all the documents in the user specified collection
const querySnapshot = await getDocs(userTodoListCollection);
// extract the data from each document and and return the data from each document
const todoItems = querySnapshot.docs.map((doc) => doc.data());
return todoItems;
} catch (error) {
console.error("Error Fetching data:", error);
throw new Error("Failed to fetch all items in collection");
}
}