Class: QuickSearch::PhoneNumberQuickSearch
- Inherits:
-
BaseQuickSearch
- Object
- BaseQuickSearch
- QuickSearch::PhoneNumberQuickSearch
- Defined in:
- app/queries/quick_search/phone_number_quick_search.rb
Overview
Query object: phone number quick search.
Class Method Summary collapse
-
.handles_types ⇒ Object
Declare friendly types this searcher supports (used by BaseQuickSearch#handles_query_type?).
Instance Method Summary collapse
- #extract_term(query) ⇒ Object
-
#find(params, _max_records = nil, existing_results = []) ⇒ Object
Accept filter types from params passed through the chain.
- #perform_find(term, _existing_results = []) ⇒ Object
Class Method Details
.handles_types ⇒ Object
Declare friendly types this searcher supports (used by BaseQuickSearch#handles_query_type?)
5 6 7 |
# File 'app/queries/quick_search/phone_number_quick_search.rb', line 5 def self.handles_types %i[contact customer employee] end |
Instance Method Details
#extract_term(query) ⇒ Object
9 10 11 |
# File 'app/queries/quick_search/phone_number_quick_search.rb', line 9 def extract_term(query) PhoneNumber.parse(query)&.to_s end |
#find(params, _max_records = nil, existing_results = []) ⇒ Object
Accept filter types from params passed through the chain
30 31 32 33 |
# File 'app/queries/quick_search/phone_number_quick_search.rb', line 30 def find(params, _max_records = nil, existing_results = []) @filter_types = params && params[:entity_types] super end |
#perform_find(term, _existing_results = []) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/queries/quick_search/phone_number_quick_search.rb', line 13 def perform_find(term, _existing_results = []) scope = ContactPoint.joins(:party).includes(party: :profile_image).where.not(Party[:inactive].eq(true)).find_phones(term) # If an entity type filter is present (e.g., contact, customer, employee), limit to those parties allowed_types = Array(@filter_types || []).map(&:to_s) if allowed_types.present? type_map = { 'contact' => 'Contact', 'customer' => 'Customer', 'employee' => 'Employee' } party_types = allowed_types.filter_map { |t| type_map[t] } scope = scope.where(Party[:type].in(party_types)) if party_types.any? end scope end |