Module: ContactQueries
- Extended by:
- ActiveSupport::Concern
- Includes:
- Memery
- Included in:
- Contact
- Defined in:
- app/models/concerns/contact_queries.rb
Overview
Aggregate query helpers for Contact: opportunities, orders, communications, and dependents.
Instance Method Summary collapse
-
#all_contact_points ⇒ ActiveRecord::Relation<ContactPoint>
Contact points on this party and on the parent customer (when present).
-
#all_email_contact_points ⇒ ActiveRecord::Relation<ContactPoint>
Email-type rows from #all_contact_points.
-
#all_emails ⇒ Array<String>
Distinct email strings on this contact’s own ContactPoint rows.
-
#all_opportunities ⇒ ActiveRecord::Relation
Delegated to Query::PartyScopedOpportunities.
-
#all_orders ⇒ ActiveRecord::Relation
Delegated to Query::PartyScopedOrders.
-
#all_related_communications ⇒ ActiveRecord::Relation
Delegated to Query::ContactRelatedCommunications.
-
#dependents ⇒ Hash{Symbol => Array<Integer>}
IDs of related CRM objects used for delete / deactivate guards.
Instance Method Details
#all_contact_points ⇒ ActiveRecord::Relation<ContactPoint>
Contact points on this party and on the parent customer (when present).
26 27 28 |
# File 'app/models/concerns/contact_queries.rb', line 26 def all_contact_points ContactPoint.where(party_id: [id, customer_id].compact).sorted end |
#all_email_contact_points ⇒ ActiveRecord::Relation<ContactPoint>
Returns email-type rows from #all_contact_points.
31 32 33 |
# File 'app/models/concerns/contact_queries.rb', line 31 def all_email_contact_points all_contact_points.emails end |
#all_emails ⇒ Array<String>
Distinct email strings on this contact’s own ContactPoint rows.
38 39 40 |
# File 'app/models/concerns/contact_queries.rb', line 38 def all_emails contact_points.emails.pluck(:detail).uniq end |
#all_opportunities ⇒ ActiveRecord::Relation
Returns delegated to Query::PartyScopedOpportunities.
14 15 16 |
# File 'app/models/concerns/contact_queries.rb', line 14 def all_opportunities Query::PartyScopedOpportunities.call(self) end |
#all_orders ⇒ ActiveRecord::Relation
Returns delegated to Query::PartyScopedOrders.
19 20 21 |
# File 'app/models/concerns/contact_queries.rb', line 19 def all_orders Query::PartyScopedOrders.call(self) end |
#all_related_communications ⇒ ActiveRecord::Relation
Returns delegated to Query::ContactRelatedCommunications.
43 44 45 |
# File 'app/models/concerns/contact_queries.rb', line 43 def Query::ContactRelatedCommunications.call(self) end |
#dependents ⇒ Hash{Symbol => Array<Integer>}
IDs of related CRM objects used for delete / deactivate guards.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/models/concerns/contact_queries.rb', line 50 def dependents r = { opportunities: opportunity_ids, orders: order_ids, opportunity_participants: opportunity_participant_ids, quotes: quote_ids, spiff_orders: spiff_order_ids, spiff_enrollments: spiff_enrollment_ids } r.compact_blank! end |