Class: Query::CustomerRelatedCommunications
- Inherits:
-
Object
- Object
- Query::CustomerRelatedCommunications
- Defined in:
- app/services/query/customer_related_communications.rb
Overview
Builds the seven-way Communication union for a Customer:
- recipient_party_id IN (customer + active contact ids)
- sender_party_id IN (same scope)
- CommunicationRecipient via contact_points belonging to that scope
- resource = customer's Quotes
- resource = customer's Orders
- resource = customer's Opportunities
- resource = the Customer record itself
Returns a Communication relation usable in further .where / .order calls.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(customer) ⇒ CustomerRelatedCommunications
constructor
A new instance of CustomerRelatedCommunications.
Constructor Details
#initialize(customer) ⇒ CustomerRelatedCommunications
Returns a new instance of CustomerRelatedCommunications.
18 19 20 |
# File 'app/services/query/customer_related_communications.rb', line 18 def initialize(customer) @customer = customer end |
Class Method Details
.call(customer) ⇒ Object
14 15 16 |
# File 'app/services/query/customer_related_communications.rb', line 14 def self.call(customer) new(customer).call end |
Instance Method Details
#call ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/services/query/customer_related_communications.rb', line 22 def call party_ids = @customer.self_and_contacts_party_ids_arr Communication.union( Communication.where(recipient_party_id: party_ids), Communication.where(sender_party_id: party_ids), via_contact_points(party_ids), Communication.where(resource_type: 'Quote', resource_id: @customer.quotes.select(:id)), Communication.where(resource_type: 'Order', resource_id: @customer.orders.select(:id)), Communication.where(resource_type: 'Opportunity', resource_id: @customer.opportunities.select(:id)), Communication.where(resource_type: 'Customer', resource_id: @customer.id) ) end |