Skip to content

Commit

Permalink
Merge branch 'release-62' into ea/ce-decline-cancel-tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
eanders authored Aug 8, 2024
2 parents 3f50cdf + 2b27391 commit a4948b8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
11 changes: 11 additions & 0 deletions app/models/concerns/client_opportunity_matches/has_decisions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ module HasDecisions
inverse_of: :match,
dependent: :destroy

has_one :initial_decision, -> do
initial_decisions = one_for_column(
order_clause: MatchDecisions::Base.arel_table[:id].asc,
source_arel_table: MatchDecisions::Base.arel_table,
group_on: :match_id,
scope: MatchDecisions::Base.initialized_decisions,
)
where(id: initial_decisions)
end, class_name: 'MatchDecisions::Base',
foreign_key: 'match_id'

# macro to set up a decision within a match
def self.has_decision(decision_type, decision_class_name: nil, notification_class_name: nil) # rubocop:disable Naming/PredicateName
decision_class_name ||= "MatchDecisions::#{decision_type.to_s.camelize}"
Expand Down
3 changes: 3 additions & 0 deletions app/models/match_decisions/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class Base < ApplicationRecord
attr_accessor :shelter_expiration

scope :pending, -> { where(status: [:pending, :other_clients_canceled]) }
scope :initialized_decisions, -> do
where.not(status: nil)
end
scope :awaiting_action, -> do
where(status: [:pending, :other_clients_canceled, :acknowledged])
end
Expand Down
7 changes: 4 additions & 3 deletions app/models/opportunity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ class Opportunity < ApplicationRecord
end

scope :available_for_poaching, -> do
available_candidate_ids = Opportunity.available_candidate.pluck(:id)
unstarted_ids = Opportunity.joins(active_matches: :match_recommendation_dnd_staff_decision).
available_candidate_ids = current_scope.available_candidate.pluck(:id)
# Join any unstarted matches
unstarted_ids = current_scope.joins(active_matches: :initial_decision).
merge(MatchDecisions::Base.pending).pluck(:id)
Opportunity.where(id: available_candidate_ids + unstarted_ids)
where(id: available_candidate_ids + unstarted_ids)
end
# after_save :run_match_engine_if_newly_available

Expand Down

0 comments on commit a4948b8

Please sign in to comment.