Skip to content

Commit

Permalink
WIP get benchmark assignees
Browse files Browse the repository at this point in the history
  • Loading branch information
nickvisut committed Dec 20, 2024
1 parent 4f45f88 commit 31c9d14
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
89 changes: 88 additions & 1 deletion src/backend/routers/iep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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
Expand Down

0 comments on commit 31c9d14

Please sign in to comment.