Skip to content

Commit

Permalink
remove due_date and trial_count from iep trpc methods, add updateBenc…
Browse files Browse the repository at this point in the history
…hmark method
  • Loading branch information
canjalal committed Jan 17, 2025
1 parent 746ed0e commit f8d9e45
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 52 deletions.
121 changes: 69 additions & 52 deletions src/backend/routers/iep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export const iep = router({
metric_name: z.string(),
attempts_per_trial: z.number().nullable(),
number_of_trials: z.number().nullable(),
due_date: z.date(),
trial_count: z.number(),
})
)
.mutation(async (req) => {
Expand All @@ -102,6 +104,8 @@ export const iep = router({
metric_name,
attempts_per_trial,
number_of_trials,
due_date,
trial_count,
} = req.input;

const result = await req.ctx.db
Expand All @@ -119,24 +123,85 @@ export const iep = router({
metric_name,
attempts_per_trial,
number_of_trials,
due_date,
trial_count,
})
.returningAll()
.executeTakeFirst();

return result;
}),

updateBenchmark: hasPara
.input(
z.object({
benchmark_id: z.string(),
goal_id: z.string().optional(),
status: z.string().optional(),
description: z.string().optional(),
setup: z.string().optional(),
instructions: z.string().optional(),
materials: z.string().optional(),
frequency: z.string().optional(),
target_level: z.number().min(0).max(100).optional(),
baseline_level: z.number().min(0).max(100).optional(),
metric_name: z.string().optional(),
attempts_per_trial: z.number().nullable().optional(),
number_of_trials: z.number().nullable().optional(),
due_date: z.date().optional(),
trial_count: z.number().optional(),
})
)
.mutation(async (req) => {
const {
benchmark_id,
goal_id,
status,
description,
setup,
instructions,
materials,
frequency,
target_level,
baseline_level,
metric_name,
attempts_per_trial,
number_of_trials,
due_date,
trial_count,
} = req.input;

await req.ctx.db
.updateTable("benchmark")
.set({
goal_id,
status,
description,
setup,
instructions,
materials,
frequency,
target_level,
baseline_level,
metric_name,
attempts_per_trial,
number_of_trials,
due_date,
trial_count,
})
.where("benchmark.benchmark_id", "=", benchmark_id)
.execute();
}),

addTask: hasCaseManager
.input(
z.object({
benchmark_id: z.string(),
assignee_id: z.string(),
due_date: z.date(),
trial_count: z.number(),
})
)
.mutation(async (req) => {
const { benchmark_id, assignee_id, due_date, trial_count } = req.input;
const { benchmark_id, assignee_id } = req.input;

const existingTask = await req.ctx.db
.selectFrom("task")
Expand All @@ -156,8 +221,6 @@ export const iep = router({
.values({
benchmark_id,
assignee_id,
due_date,
trial_count,
})
.returningAll()
.executeTakeFirst();
Expand All @@ -169,12 +232,10 @@ export const iep = router({
z.object({
benchmark_id: z.string().uuid(),
para_ids: z.string().uuid().array(),
due_date: z.date().optional(),
trial_count: z.number().optional(),
})
)
.mutation(async (req) => {
const { benchmark_id, para_ids, due_date, trial_count } = req.input;
const { benchmark_id, para_ids } = req.input;

const existingTasks = await req.ctx.db
.selectFrom("task")
Expand All @@ -195,56 +256,12 @@ export const iep = router({
para_ids.map((para_id) => ({
benchmark_id,
assignee_id: para_id,
due_date,
trial_count,
}))
)
.returningAll()
.executeTakeFirst();
return result;
}),
//Temporary function to easily assign tasks to self for testing
tempAddTaskToSelf: hasCaseManager
.input(
z.object({
benchmark_id: z.string(),
due_date: z.date(),
trial_count: z.number(),
})
)
.mutation(async (req) => {
const { benchmark_id, due_date, trial_count } = req.input;
const { userId } = req.ctx.auth;

const shouldAdd = await req.ctx.db
.selectFrom("task")
.selectAll()
.where((eb) =>
eb.and([
eb("benchmark_id", "=", benchmark_id),
eb("assignee_id", "=", userId),
])
)
.executeTakeFirst();

// Prevent multiple assignments of the same task
if (shouldAdd !== undefined) {
return null;
}

const result = await req.ctx.db
.insertInto("task")
.values({
benchmark_id,
assignee_id: userId,
due_date,
trial_count,
})
.returningAll()
.executeTakeFirst();

return result;
}),

addTrialData: hasPara
.input(
Expand Down
1 change: 1 addition & 0 deletions src/components/benchmarks/BenchmarkAssignmentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const BenchmarkAssignmentModal = (
await assignTaskToPara.mutateAsync({
benchmark_id: props.benchmark_id,
para_ids: selectedParaIds,
// this should be written to benchmarks:
due_date:
assignmentDuration.type === "until_date"
? assignmentDuration.date
Expand Down

0 comments on commit f8d9e45

Please sign in to comment.