From b51a060762a4ed5574e168089a126d6473d701b8 Mon Sep 17 00:00:00 2001 From: amantri <829820+amantri@users.noreply.github.com> Date: Sun, 31 Mar 2024 17:50:34 -0700 Subject: [PATCH] WIP - For a para, show the student list associated with the CM(s) the para is assigned to Currently, this doesn't work completely --- src/backend/routers/case_manager.ts | 29 +++++++++++++++++++++++++ src/backend/routers/para.ts | 12 +++++++++++ src/components/table/table.tsx | 11 ++++++++-- src/pages/students/index.tsx | 33 +++++++++++++++++++++++++++-- 4 files changed, 81 insertions(+), 4 deletions(-) diff --git a/src/backend/routers/case_manager.ts b/src/backend/routers/case_manager.ts index d739a523..4be2f73e 100644 --- a/src/backend/routers/case_manager.ts +++ b/src/backend/routers/case_manager.ts @@ -17,6 +17,35 @@ export const case_manager = router({ return result; }), + getStudentsAndIepInfo: authenticatedProcedure + .input( + z.object({ + userId: z.string().uuid(), + }) + ) + .query(async (req) => { + const { userId } = req.input; + + const studentData = await req.ctx.db + .selectFrom("iep") + .fullJoin("student", (join) => + join.onRef("student.student_id", "=", "iep.student_id") + ) + .where("assigned_case_manager_id", "=", userId) + .select([ + "student.student_id as student_id", + "first_name", + "last_name", + "student.email", + "iep.iep_id as iep_id", + "iep.end_date as end_date", + "student.grade as grade", + ]) + .execute(); + + return studentData; + }), + getMyStudentsAndIepInfo: authenticatedProcedure.query(async (req) => { const { userId } = req.ctx.auth; diff --git a/src/backend/routers/para.ts b/src/backend/routers/para.ts index c5e735af..e9d402da 100644 --- a/src/backend/routers/para.ts +++ b/src/backend/routers/para.ts @@ -31,6 +31,18 @@ export const para = router({ return result; }), + getMyCaseManagers: authenticatedProcedure.query(async (req) => { + const { userId } = req.ctx.auth; + + const result = await req.ctx.db + .selectFrom("paras_assigned_to_case_manager") + .where("para_id", "=", userId) + .select("case_manager_id") + .execute(); + + return result; + }), + createPara: authenticatedProcedure .input( z.object({ diff --git a/src/components/table/table.tsx b/src/components/table/table.tsx index b935dc87..ac0a74f2 100644 --- a/src/components/table/table.tsx +++ b/src/components/table/table.tsx @@ -253,6 +253,7 @@ interface EnhancedTableProps { onSubmit: (event: React.FormEvent) => void; headCells: Column[]; type: "Students" | "Staff"; + isReadWrite?: boolean; } /** @@ -265,7 +266,13 @@ interface EnhancedTableProps { export default function EnhancedTable< Person extends StudentWithIep | Para, Column extends HeadCell ->({ people, onSubmit, headCells, type }: EnhancedTableProps) { +>({ + people, + onSubmit, + headCells, + type, + isReadWrite, +}: EnhancedTableProps) { const router = useRouter(); const [order, setOrder] = useState("asc"); @@ -369,7 +376,7 @@ export default function EnhancedTable< onRequestSort={handleRequestSort} /> - {showInput && ( + {showInput && isReadWrite && ( { const utils = trpc.useContext(); - const { data: students, isLoading } = - trpc.case_manager.getMyStudentsAndIepInfo.useQuery(); + + const isCaseManager = trpc.user.isCaseManager.useQuery().data ?? false; + + let students; + let isLoading; + + const { data: me } = trpc.user.getMe.useQuery(); + + if (isCaseManager) { + ({ data: students, isLoading } = + trpc.case_manager.getStudentsAndIepInfo.useQuery({ + userId: me!.user_id, + })); + } else { + const result = trpc.para.getMyCaseManagers.useQuery(); + console.log("result=", result.data); + // let ({ data, isLoading } = trpc.para.getMyCaseManagers.useQuery()); + // students = []; + result.data?.forEach((row) => { + console.log(row.case_manager_id); + // const data = trpc.case_manager.getStudentsAndIepInfo.useQuery({userId: row.case_manager_id}); + ({ data: students, isLoading } = + trpc.case_manager.getStudentsAndIepInfo.useQuery({ + userId: row.case_manager_id, + })); + console.log(students); + }); + // students.push(data.students); + // } + } const createStudent = trpc.case_manager.addStudent.useMutation({ onSuccess: () => utils.case_manager.getMyStudentsAndIepInfo.invalidate(), @@ -79,6 +107,7 @@ const Students = () => { onSubmit={handleSubmit} headCells={headCells} type="Students" + isReadWrite={isCaseManager} /> ); };