mirror of
https://github.com/urosran/cally.git
synced 2025-11-26 00:24:53 +00:00
- 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:
@ -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();
|
||||
|
||||
Reference in New Issue
Block a user