Skip to content

Commit

Permalink
Stop updating statuses
Browse files Browse the repository at this point in the history
This updates the ApplicationFormStatusUpdater service to stop updating
the status (and related fields) as we're going to stop using them and
instead rely on the replacements.
  • Loading branch information
thomasleese committed Sep 24, 2023
1 parent 6129708 commit 84b7205
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 256 deletions.
214 changes: 79 additions & 135 deletions app/lib/application_form_status_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,6 @@ def initialize(application_form:, user:)

def call
ActiveRecord::Base.transaction do
application_form.update!(
overdue_further_information:,
overdue_professional_standing: overdue_lops,
overdue_qualification:,
overdue_reference:,
received_further_information:,
received_professional_standing: received_lops,
received_qualification:,
received_reference:,
waiting_on_further_information:,
waiting_on_professional_standing: waiting_on_lops,
waiting_on_qualification:,
waiting_on_reference:,
)

if (old_status = application_form.status) != status
application_form.update!(status:)
create_timeline_event(
event_type: "state_changed",
old_state: old_status,
new_state: status,
)
end

if (old_action_required_by = application_form.action_required_by) !=
action_required_by
application_form.update!(action_required_by:)
Expand Down Expand Up @@ -61,117 +37,6 @@ def call

attr_reader :application_form, :user

def overdue_further_information
overdue?(requestables: further_information_requests)
end

def overdue_lops
return false if teaching_authority_provides_written_statement
overdue?(requestables: professional_standing_requests)
end

def overdue_qualification
overdue?(requestables: qualification_requests)
end

def overdue_reference
return false if references_verified
overdue?(requestables: reference_requests)
end

def received_further_information
received?(requestables: further_information_requests)
end

def received_lops
return false if teaching_authority_provides_written_statement

professional_standing_requests
.reject(&:reviewed?)
.any? do |requestable|
requestable.received? || requestable.ready_for_review
end
end

def received_qualification
received?(requestables: qualification_requests)
end

def received_reference
return false unless received?(requestables: reference_requests)

received_requests = reference_requests.filter(&:received?)

months_count =
WorkHistoryDuration.new(
work_history_relation:
application_form.work_histories.where(
id: received_requests.map(&:work_history_id),
),
).count_months

most_recent_reference_request =
reference_requests.max_by { |request| request.work_history.start_date }

if months_count < 9
false
elsif months_count >= 20 &&
(region.checks_available? || most_recent_reference_request&.received?)
true
else
reference_requests.filter(&:requested?).empty?
end
end

def waiting_on_further_information
waiting_on?(requestables: further_information_requests)
end

def waiting_on_lops
waiting_on?(requestables: professional_standing_requests)
end

def waiting_on_qualification
waiting_on?(requestables: qualification_requests)
end

def waiting_on_reference
return false if references_verified
waiting_on?(requestables: reference_requests)
end

def status
@status ||=
if dqt_trn_request&.potential_duplicate?
"potential_duplicate_in_dqt"
elsif application_form.withdrawn_at.present?
"withdrawn"
elsif application_form.declined_at.present?
"declined"
elsif application_form.awarded_at.present?
"awarded"
elsif dqt_trn_request.present?
"awarded_pending_checks"
elsif preliminary_check?
"preliminary_check"
elsif overdue_further_information || overdue_lops ||
overdue_qualification || overdue_reference
"overdue"
elsif received_further_information || received_lops ||
received_qualification || received_reference
"received"
elsif waiting_on_further_information || waiting_on_lops ||
waiting_on_qualification || waiting_on_reference
"waiting_on"
elsif assessment&.any_not_preliminary_section_finished?
"assessment_in_progress"
elsif application_form.submitted_at.present?
"submitted"
else
"draft"
end
end

def action_required_by
@action_required_by ||=
if application_form.withdrawn_at.present? ||
Expand Down Expand Up @@ -276,6 +141,85 @@ def requestable_statuses
.filter { |column| send(column) }
end

def overdue_further_information
overdue?(requestables: further_information_requests)
end

def overdue_lops
return false if teaching_authority_provides_written_statement
overdue?(requestables: professional_standing_requests)
end

def overdue_qualification
overdue?(requestables: qualification_requests)
end

def overdue_reference
return false if references_verified
overdue?(requestables: reference_requests)
end

def received_further_information
received?(requestables: further_information_requests)
end

def received_lops
return false if teaching_authority_provides_written_statement

professional_standing_requests
.reject(&:reviewed?)
.any? do |requestable|
requestable.received? || requestable.ready_for_review
end
end

def received_qualification
received?(requestables: qualification_requests)
end

def received_reference
return false unless received?(requestables: reference_requests)

received_requests = reference_requests.filter(&:received?)

months_count =
WorkHistoryDuration.new(
work_history_relation:
application_form.work_histories.where(
id: received_requests.map(&:work_history_id),
),
).count_months

most_recent_reference_request =
reference_requests.max_by { |request| request.work_history.start_date }

if months_count < 9
false
elsif months_count >= 20 &&
(region.checks_available? || most_recent_reference_request&.received?)
true
else
reference_requests.filter(&:requested?).empty?
end
end

def waiting_on_further_information
waiting_on?(requestables: further_information_requests)
end

def waiting_on_lops
waiting_on?(requestables: professional_standing_requests)
end

def waiting_on_qualification
waiting_on?(requestables: qualification_requests)
end

def waiting_on_reference
return false if references_verified
waiting_on?(requestables: reference_requests)
end

def further_information_requests
@further_information_requests ||=
assessment&.further_information_requests&.to_a || []
Expand Down
Loading

0 comments on commit 84b7205

Please sign in to comment.