mirror of
https://github.com/urosran/cally.git
synced 2025-11-26 16:34:54 +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 { useQuery } from "react-query";
|
||||||
import firestore from "@react-native-firebase/firestore";
|
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";
|
import { IToDo } from "@/hooks/firebase/types/todoData";
|
||||||
|
|
||||||
export const useGetTodos = () => {
|
export const useGetTodos = () => {
|
||||||
const { user, profileData } = useAuthContext();
|
const { user, profileData } = useAuthContext();
|
||||||
//TODO: Add role based filtering for todos
|
|
||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ["todos", user?.uid],
|
queryKey: ["todos", user?.uid],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const snapshot = await firestore()
|
|
||||||
.collection("Todos")
|
let snapshot;
|
||||||
.where("familyId", "==", profileData?.familyId)
|
if (profileData?.userType === ProfileType.PARENT) {
|
||||||
.get();
|
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) => {
|
return snapshot.docs.map((doc) => {
|
||||||
const data = doc.data();
|
const data = doc.data();
|
||||||
|
|||||||
Reference in New Issue
Block a user