From 31c9d141f46415d39d46a969a6423f3994a1c02d Mon Sep 17 00:00:00 2001 From: Nick Visutsithiwong <2823112+nickvisut@users.noreply.github.com> Date: Thu, 19 Dec 2024 23:24:48 -0800 Subject: [PATCH] WIP get benchmark assignees --- package.json | 1 + src/backend/routers/iep.ts | 89 +++++++++++++++++++++++++++++++++++++- 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index adaac655..06d7d6cb 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "type-css:check": "npx tcm src --listDifferent", "test": "next build --no-lint && ava", "test-storybook": "test-storybook --maxWorkers=2", + "docker-reup": "docker compose -f supporting_services/docker-compose.yml up -d", "db:migrate": "npx tsx src/backend/scripts/migrate-database.ts", "db:reset": "npx tsx src/backend/scripts/reset-database.ts", "db:seed": "npx tsx src/backend/scripts/seed-database.ts", diff --git a/src/backend/routers/iep.ts b/src/backend/routers/iep.ts index 0a66ae5f..47ad2506 100644 --- a/src/backend/routers/iep.ts +++ b/src/backend/routers/iep.ts @@ -354,6 +354,42 @@ export const iep = router({ return result; }), + //.innerJoin("task", "benchmark.benchmark_id", "task.benchmark_id") + // .innerJoin("goal", "benchmark.goal_id", "goal.goal_id") + // .innerJoin("iep", "goal.iep_id", "iep.iep_id") + // .innerJoin("student", "iep.student_id", "student.student_id") + + // "task.task_id", + // "student.first_name", + // "student.last_name", + // "goal.category", + // "benchmark.description", + // "benchmark.instructions", + // "benchmark.frequency", + // "benchmark.number_of_trials", + // "benchmark.benchmark_id", + // "task.due_date", + // "task.seen", + // "task.trial_count", + + // .select([ + // "benchmark.description", + // "benchmark.instructions", + // "benchmark.frequency", + // "benchmark.number_of_trials", + // "benchmark.benchmark_id", + // ]) + + // { + // benchmark: { + // id, + // title, + // desc, + // assignees: [ + // { id:, name } + // ] + // } + // } getBenchmark: hasCaseManager .input( z.object({ @@ -363,12 +399,63 @@ export const iep = router({ .query(async (req) => { const { benchmark_id } = req.input; + // NOTE: existing code const result = await req.ctx.db .selectFrom("benchmark") .where("benchmark.benchmark_id", "=", benchmark_id) - .selectAll() // add second query to get the tasks associated with benchmark + .selectAll() // works + // .select("*") // doesn't work, but maybe it'll work if we do the function form .execute(); return result; + + // // NOTE: no errors, but the app may blow up b/c we're returning multiple rows + // const result = await req.ctx.db + // .selectFrom("benchmark") + // .innerJoin("task", "benchmark.benchmark_id", "task.benchmark_id") + // .innerJoin("user", "task.assignee_id", "user.user_id") + // .where("benchmark.benchmark_id", "=", benchmark_id) + // .selectAll() + // .execute(); + // return result; + + // const result = await req.ctx.db + // .selectFrom("benchmark") + // .innerJoin("task", "benchmark.benchmark_id", "task.benchmark_id") + // .innerJoin("user", "task.assignee_id", "user.user_id") + // .where("task.assignee_id", "=", "user.user_id") + // .where("benchmark.benchmark_id", "=", benchmark_id) + // .select((eb) => [ + // "*", + // // jsonArrayFrom( + // // eb + // // .selectFrom("user") + // // .selectAll() + // // .whereRef("task.assignee_id", "=", "user.user_id") + // // .orderBy("user.first_name") + // // ).as("assignees"), + // jsonArrayFrom( + // eb + // .selectFrom("trial_data") + // .select([ + // "trial_data.trial_data_id", + // "trial_data.success", + // "trial_data.unsuccess", + // "trial_data.submitted", + // "trial_data.notes", + // "trial_data.created_at", + // ]) + // .whereRef("trial_data.task_id", "=", "task.task_id") + // .whereRef( + // "trial_data.created_by_user_id", + // "=", + // "task.assignee_id" + // ) + // .orderBy("trial_data.created_at") + // ).as("assignees"), + // ]) + // .executeTakeFirstOrThrow(); + // // .execute(); + // return result; }), getBenchmarkByAssignee: hasCaseManager