Skip to content

Commit

Permalink
Changes to SQL to allow for ignored columns
Browse files Browse the repository at this point in the history
  • Loading branch information
elceebee committed Sep 27, 2024
1 parent adcbf0b commit 80a2f36
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 45 deletions.
49 changes: 25 additions & 24 deletions app/services/candidate_interface/sort_application_choices.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
module CandidateInterface
class SortApplicationChoices
def self.call(application_choices:)
scope = application_choices.from <<~WITH_GROUP.squish
(
SELECT application.*,
CASE
WHEN (status IN ('offer')) THEN 'offers_received'
WHEN (status IN ('unsubmitted', 'application_not_sent', 'cancelled')) THEN 'draft'
WHEN (status IN ('rejected', 'conditions_not_met')) THEN 'unsuccessful'
WHEN (status IN ('interviewing', 'inactive', 'awaiting_provider_decision')) THEN 'in_progress'
WHEN (status IN ('offer_withdrawn', 'withdrawn')) THEN 'withdrawn'
WHEN (status IN ('declined')) THEN 'declined'
ELSE ''
END AS application_choices_group_name,
CASE
WHEN (status IN ('offer')) THEN 1
WHEN (status IN ('unsubmitted', 'application_not_sent', 'cancelled')) THEN 2
WHEN (status IN ('rejected', 'conditions_not_met')) THEN 3
WHEN (status IN ('interviewing', 'inactive', 'awaiting_provider_decision')) THEN 4
WHEN (status IN ('offer_withdrawn', 'withdrawn')) THEN 5
WHEN (status IN ('declined')) THEN 6
ELSE 10
END AS application_choices_group_number
FROM application_choices application
) AS application_choices
WITH_GROUP
# Explicitly list the columns so that the 'ignored_columns' on the model are not included in the raw SQL.
columns = ApplicationChoice.new.attribute_names.map { |key| "application_choices.#{key}" }.join(', ')

scope = application_choices.select(
"#{columns},
CASE
WHEN status IN ('offer') THEN 'offers_received'
WHEN status IN ('unsubmitted', 'application_not_sent', 'cancelled') THEN 'draft'
WHEN status IN ('rejected', 'conditions_not_met') THEN 'unsuccessful'
WHEN status IN ('interviewing', 'inactive', 'awaiting_provider_decision') THEN 'in_progress'
WHEN status IN ('offer_withdrawn', 'withdrawn') THEN 'withdrawn'
WHEN status IN ('declined') THEN 'declined'
ELSE ''
END AS application_choices_group_name,
CASE
WHEN status IN ('offer') THEN 1
WHEN status IN ('unsubmitted', 'application_not_sent', 'cancelled') THEN 2
WHEN status IN ('rejected', 'conditions_not_met') THEN 3
WHEN status IN ('interviewing', 'inactive', 'awaiting_provider_decision') THEN 4
WHEN status IN ('offer_withdrawn', 'withdrawn') THEN 5
WHEN status IN ('declined') THEN 6
ELSE 10
END AS application_choices_group_number",
)

scope.order('application_choices_group_number ASC, application_choices.sent_to_provider_at DESC')
end
end
Expand Down
37 changes: 18 additions & 19 deletions app/services/provider_interface/sort_application_choices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,25 @@ def self.call(application_choices:)
end

def self.for_task_view(application_choices)
application_choices.from <<~WITH_TASK_VIEW_GROUP.squish
(
SELECT a.*,
CASE
WHEN #{inactive} THEN 1
WHEN #{awaiting_provider_decision} THEN 2
WHEN #{deferred_offers_pending_reconfirmation} THEN 3
WHEN #{give_feedback_for_rbd} THEN 4
WHEN #{interviewing} THEN 5
WHEN #{pending_conditions_previous_cycle} THEN 6
WHEN #{waiting_on_candidate} THEN 7
WHEN #{pending_conditions_current_cycle} THEN 8
WHEN #{successful_candidates} THEN 9
WHEN #{deferred_offers_current_cycle} THEN 10
ELSE 999
END AS task_view_group
# Explicitly list the columns so that the 'ignored_columns' on the model are not included in the raw SQL.
columns = ApplicationChoice.new.attribute_names.map { |key| "application_choices.#{key}" }.join(', ')

FROM application_choices a
) AS application_choices
WITH_TASK_VIEW_GROUP
application_choices.select(
"#{columns},
CASE
WHEN #{inactive} THEN 1
WHEN #{awaiting_provider_decision} THEN 2
WHEN #{deferred_offers_pending_reconfirmation} THEN 3
WHEN #{give_feedback_for_rbd} THEN 4
WHEN #{interviewing} THEN 5
WHEN #{pending_conditions_previous_cycle} THEN 6
WHEN #{waiting_on_candidate} THEN 7
WHEN #{pending_conditions_current_cycle} THEN 8
WHEN #{successful_candidates} THEN 9
WHEN #{deferred_offers_current_cycle} THEN 10
ELSE 999
END AS task_view_group",
)
end

def self.deferred_offers_pending_reconfirmation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@

it 'according to their task_view_group, rbd and updated_at' do
expected = application_choices.map(&:id)
actual = described_class.call(application_choices: ApplicationChoice.all).pluck(:id)
expect(actual.to_a).to eq(expected)
actual = described_class.call(application_choices: ApplicationChoice.all).map(&:id)
expect(actual).to eq(expected)
end
end
end

0 comments on commit 80a2f36

Please sign in to comment.