Skip to content

Commit

Permalink
Fix code climate
Browse files Browse the repository at this point in the history
  • Loading branch information
kcdragon committed Jul 30, 2023
1 parent cf4be91 commit a0360da
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions app/controllers/bulk_court_dates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@ def create

case_group_id = params[:court_date][:case_group_id]
if case_group_id.empty?
@court_date = CourtDate.new(court_date_params(nil))
@court_date.errors.add(:base, "Case group must be selected.")
@court_date = build_court_date_with_error_message
render :new
return
end

case_group = current_organization.case_groups.find(case_group_id)

court_dates = case_group.casa_cases.map do |casa_case|
CourtDate.new(court_date_params(casa_case).merge(casa_case: casa_case))
end
court_dates = build_court_dates(case_group)

court_date_with_error = nil
ActiveRecord::Base.transaction do
Expand All @@ -43,4 +39,18 @@ def create
redirect_to new_bulk_court_date_path, notice: "#{court_dates.size} #{"court date".pluralize(court_dates.size)} created!"
end
end

private

def build_court_date_with_error_message
court_date = CourtDate.new(court_date_params(nil))
court_date.errors.add(:base, "Case group must be selected.")
court_date
end

def build_court_dates(case_group)
case_group.casa_cases.map do |casa_case|
CourtDate.new(court_date_params(casa_case).merge(casa_case: casa_case))
end
end
end

0 comments on commit a0360da

Please sign in to comment.