Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/backend/routers/case_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 12 additions & 0 deletions src/backend/routers/para.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
11 changes: 9 additions & 2 deletions src/components/table/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ interface EnhancedTableProps<Person, Column> {
onSubmit: (event: React.FormEvent<HTMLFormElement>) => void;
headCells: Column[];
type: "Students" | "Staff";
isReadWrite?: boolean;
}

/**
Expand All @@ -265,7 +266,13 @@ interface EnhancedTableProps<Person, Column> {
export default function EnhancedTable<
Person extends StudentWithIep | Para,
Column extends HeadCell
>({ people, onSubmit, headCells, type }: EnhancedTableProps<Person, Column>) {
>({
people,
onSubmit,
headCells,
type,
isReadWrite,
}: EnhancedTableProps<Person, Column>) {
const router = useRouter();

const [order, setOrder] = useState<Order>("asc");
Expand Down Expand Up @@ -369,7 +376,7 @@ export default function EnhancedTable<
onRequestSort={handleRequestSort}
/>
<TableBody>
{showInput && (
{showInput && isReadWrite && (
<EnhancedTableInput
inputCells={headCells}
type={type}
Expand Down
33 changes: 31 additions & 2 deletions src/pages/students/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,36 @@ import PersonTable, {

const Students = () => {
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(),
Expand Down Expand Up @@ -79,6 +107,7 @@ const Students = () => {
onSubmit={handleSubmit}
headCells={headCells}
type="Students"
isReadWrite={isCaseManager}
/>
);
};
Expand Down