Module: OpportunityBriefing::RelatedRecords
- Defined in:
- app/services/opportunity_briefing/related_records.rb
Overview
Centralizes the cross-resource record scopes that make up an opportunity
briefing. Activities and communications can hang off the opportunity,
quotes, rooms, orders, or a linked call record.
Class Method Summary collapse
- .activities_for(opportunity) ⇒ Object
- .call_records_for(opportunity) ⇒ Object
- .communications_for(opportunity) ⇒ Object
Class Method Details
.activities_for(opportunity) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/services/opportunity_briefing/related_records.rb', line 9 def activities_for(opportunity) branches = [ { opportunity_id: opportunity.id }, { resource_type: 'Opportunity', resource_id: opportunity.id } ] branches << { resource_type: 'Quote', resource_id: opportunity.quote_ids } if opportunity.quote_ids.any? branches << { resource_type: 'RoomConfiguration', resource_id: opportunity.room_configuration_ids } if opportunity.room_configuration_ids.any? branches << { resource_type: 'Order', resource_id: opportunity.order_ids } if opportunity.order_ids.any? Activity.where.any_of(*branches) end |
.call_records_for(opportunity) ⇒ Object
25 26 27 28 29 30 31 |
# File 'app/services/opportunity_briefing/related_records.rb', line 25 def call_records_for(opportunity) activity_scope = activities_for(opportunity) ids = activity_scope.where(resource_type: 'CallRecord').where.not(resource_id: nil).pluck(:resource_id) ids.concat(activity_scope.where.not(call_record_id: nil).pluck(:call_record_id)) CallRecord.where(id: ids.compact.uniq) end |
.communications_for(opportunity) ⇒ Object
21 22 23 |
# File 'app/services/opportunity_briefing/related_records.rb', line 21 def communications_for(opportunity) opportunity. end |