diff --git a/app/models/casa_case.rb b/app/models/casa_case.rb index 5b8d20e315..6dc84b9c00 100644 --- a/app/models/casa_case.rb +++ b/app/models/casa_case.rb @@ -4,6 +4,7 @@ class CasaCase < ApplicationRecord has_many :case_assignments, dependent: :destroy has_many(:volunteers, through: :case_assignments, source: :volunteer, class_name: "User") has_many :case_contacts, dependent: :destroy + has_many :past_court_dates, dependent: :destroy validates :case_number, uniqueness: {case_sensitive: false}, presence: true belongs_to :hearing_type, optional: true belongs_to :judge, optional: true diff --git a/app/models/past_court_date.rb b/app/models/past_court_date.rb new file mode 100644 index 0000000000..bb81b2283b --- /dev/null +++ b/app/models/past_court_date.rb @@ -0,0 +1,22 @@ +class PastCourtDate < ApplicationRecord + belongs_to :casa_case +end + +# == Schema Information +# +# Table name: past_court_dates +# +# id :bigint not null, primary key +# date :datetime not null +# created_at :datetime not null +# updated_at :datetime not null +# casa_case_id :bigint not null +# +# Indexes +# +# index_past_court_dates_on_casa_case_id (casa_case_id) +# +# Foreign Keys +# +# fk_rails_... (casa_case_id => casa_cases.id) +# diff --git a/app/views/casa_cases/edit.html.erb b/app/views/casa_cases/edit.html.erb index e5dce293b3..72ed68470b 100644 --- a/app/views/casa_cases/edit.html.erb +++ b/app/views/casa_cases/edit.html.erb @@ -7,6 +7,21 @@ <%= render 'form', casa_case: @casa_case %> <% end %> +
+
+
Past court dates:
+ <% if @casa_case.past_court_dates.size > 0 %> + + <% else %> + No past court dates + <% end %> +
+
+ <% if Pundit.policy(current_user, @casa_case).assign_volunteers? %> <%= render "volunteer_assignment" %> <% end %> diff --git a/db/migrate/20201024113046_create_past_court_dates.rb b/db/migrate/20201024113046_create_past_court_dates.rb new file mode 100644 index 0000000000..ed31c96ec8 --- /dev/null +++ b/db/migrate/20201024113046_create_past_court_dates.rb @@ -0,0 +1,10 @@ +class CreatePastCourtDates < ActiveRecord::Migration[6.0] + def change + create_table :past_court_dates do |t| + t.datetime :date, null: false + t.references :casa_case, null: false, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 37963f1ce9..2ffbd3e982 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -156,6 +156,14 @@ t.index ["casa_org_id"], name: "index_hearing_types_on_casa_org_id" end + create_table "past_court_dates", force: :cascade do |t| + t.datetime "date", null: false + t.bigint "casa_case_id", null: false + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["casa_case_id"], name: "index_past_court_dates_on_casa_case_id" + end + create_table "judges", force: :cascade do |t| t.bigint "casa_org_id", null: false t.datetime "created_at", precision: 6, null: false @@ -225,6 +233,9 @@ add_foreign_key "case_assignments", "users", column: "volunteer_id" add_foreign_key "case_contacts", "casa_cases" add_foreign_key "case_contacts", "users", column: "creator_id" + + + add_foreign_key "past_court_dates", "casa_cases" add_foreign_key "judges", "casa_orgs" add_foreign_key "supervisor_volunteers", "users", column: "supervisor_id" add_foreign_key "supervisor_volunteers", "users", column: "volunteer_id" diff --git a/lib/tasks/scheduler.rake b/lib/tasks/scheduler.rake index a2e5bfa9af..7f74ea7b50 100644 --- a/lib/tasks/scheduler.rake +++ b/lib/tasks/scheduler.rake @@ -8,6 +8,9 @@ end desc "Clear court dates and report information when date has passed, run by heroku scheduler" task clear_passed_dates: :environment do puts "Checking case due dates..." - CasaCase.due_date_passed.each { |key| key.clear_court_dates } + CasaCase.due_date_passed.each do |cc| + PastCourtDate.create!(date: cc.court_date, casa_case_id: cc.id) + cc.clear_court_dates + end puts "done." end