Skip to content
Open
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
39 changes: 21 additions & 18 deletions supabase/migrations/0045_document_assessment_refinements.sql
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ begin
raise exception 'Forbidden' using errcode = '42501';
end if;

select a, r.is_custom
into v_assignment, v_uses_custom_rubric
select a.* into v_assignment
from public.assignments a
join public.assignment_rubrics r on r.id = a.rubric_id
where a.id = p_assignment_id
and a.school_id = v_batch.school_id
and a.status = 'published';
Expand All @@ -57,6 +55,14 @@ begin
raise exception 'assignment_not_found' using errcode = 'P0002';
end if;

select r.is_custom into v_uses_custom_rubric
from public.assignment_rubrics r
where r.id = v_assignment.rubric_id;

if not found then
raise exception 'assignment_rubric_not_found' using errcode = 'P0002';
end if;

if not exists (
select 1
from public.profiles p
Expand Down Expand Up @@ -84,10 +90,10 @@ begin

if v_existing_id is not null then
update public.document_import_items
set student_id = p_student_id,
linked_submission_id = v_existing_id,
review_status = 'ready_for_grading',
updated_at = now()
set student_id = p_student_id,
linked_submission_id = v_existing_id,
review_status = 'ready_for_grading',
updated_at = now()
where id = p_item_id;
return v_existing_id;
end if;
Expand All @@ -100,8 +106,7 @@ begin
assignment_id, is_practice, student_id, school_id, writing_type_id, level,
topic_title, text, word_count, status, submitted_at, last_saved_at,
score_visible_to_student, uses_custom_rubric
)
values (
) values (
p_assignment_id,
false,
p_student_id,
Expand All @@ -110,27 +115,25 @@ begin
v_assignment.level,
v_assignment.title,
v_item.ocr_text,
case
when length(trim(v_item.ocr_text)) = 0 then 0
else array_length(regexp_split_to_array(trim(v_item.ocr_text), '\\s+'), 1)
case when length(trim(v_item.ocr_text)) = 0 then 0
else array_length(regexp_split_to_array(trim(v_item.ocr_text), '\s+'), 1)
end,
'submitted',
now(),
now(),
false,
coalesce(v_uses_custom_rubric, false)
)
returning id into v_submission_id;
) returning id into v_submission_id;

delete from app_private.server_import_write_context
where transaction_id = txid_current()
and student_id = p_student_id;

update public.document_import_items
set student_id = p_student_id,
linked_submission_id = v_submission_id,
review_status = 'ready_for_grading',
updated_at = now()
set student_id = p_student_id,
linked_submission_id = v_submission_id,
review_status = 'ready_for_grading',
updated_at = now()
where id = p_item_id;

return v_submission_id;
Expand Down
Loading
Loading