diff --git a/hooks/firebase/useGetTodos.ts b/hooks/firebase/useGetTodos.ts index d040519..3c96508 100644 --- a/hooks/firebase/useGetTodos.ts +++ b/hooks/firebase/useGetTodos.ts @@ -1,19 +1,27 @@ import { useQuery } from "react-query"; import firestore from "@react-native-firebase/firestore"; -import { useAuthContext } from "@/contexts/AuthContext"; -import {IToDo} from "@/hooks/firebase/types/todoData"; +import { ProfileType, useAuthContext } from "@/contexts/AuthContext"; +import { IToDo } from "@/hooks/firebase/types/todoData"; export const useGetTodos = () => { const { user, profileData } = useAuthContext(); - //TODO: Add role based filtering for todos return useQuery({ queryKey: ["todos", user?.uid], queryFn: async () => { - const snapshot = await firestore() - .collection("Todos") - .where("familyId", "==", profileData?.familyId) - .get(); + + let snapshot; + if (profileData?.userType === ProfileType.PARENT) { + snapshot = await firestore() + .collection("Todos") + .where("familyId", "==", profileData?.familyId) + .get(); + } else { + snapshot = await firestore() + .collection("Todos") + .where("assignees", "array-contains", user?.uid) + .get(); + } return snapshot.docs.map((doc) => { const data = doc.data();