- Added user based access in the todos page and fetched only the todos that are assigned to a child type profile and all the family todos to a parent type profile

This commit is contained in:
Dejan
2024-10-27 17:30:41 +01:00
parent c25ddfcdf5
commit 6a9d446c11

View File

@ -1,19 +1,27 @@
import { useQuery } from "react-query";
import firestore from "@react-native-firebase/firestore";
import { useAuthContext } from "@/contexts/AuthContext";
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()
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();