Skip to content

Commit

Permalink
Katrina feedback: more informative error message
Browse files Browse the repository at this point in the history
  • Loading branch information
canjalal committed Oct 18, 2024
1 parent c5e3db1 commit ea303ab
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- Each task should have a unique subgoal_id - assignee_id combination
-- which corresponds to a unique benchmark / para combo
ALTER TABLE task
ADD CONSTRAINT UC_Task UNIQUE (subgoal_id, assignee_id);
ADD CONSTRAINT subgoal_assignee_unique UNIQUE (subgoal_id, assignee_id);

-- Add index to allow easy queries of tasks by assignee
CREATE INDEX idx_task_assignee ON task(assignee_id);
2 changes: 1 addition & 1 deletion src/backend/db/zapatos/schema.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/backend/routers/iep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ test("addTask - no duplicate subgoal_id + assigned_id combo", async (t) => {

t.is(
error?.message,
'duplicate key value violates unique constraint "uc_task"'
"Task already exists: This subgoal has already been assigned to the same para"
);
});

Expand Down
14 changes: 14 additions & 0 deletions src/backend/routers/iep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,20 @@ export const iep = router({
.mutation(async (req) => {
const { subgoal_id, assignee_id, due_date, trial_count } = req.input;

// make sure that this goal belongs to this case manager
const existingTask = await req.ctx.db
.selectFrom("task")
.where("subgoal_id", "=", subgoal_id)
.where("assignee_id", "=", assignee_id)
.selectAll()
.executeTakeFirst();

if (existingTask) {
throw new Error(
"Task already exists: This subgoal has already been assigned to the same para"
);
}

const result = await req.ctx.db
.insertInto("task")
.values({
Expand Down

0 comments on commit ea303ab

Please sign in to comment.