Class: Customer::PruneTouchbase

Inherits:
BaseService show all
Defined in:
app/services/customer/prune_touchbase.rb

Overview

Cancels touchbase for accounts not on watch list

Defined Under Namespace

Classes: Result

Instance Attribute Summary

Attributes inherited from BaseService

#options

Instance Method Summary collapse

Methods inherited from BaseService

#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #tagged_logger

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#process(**options) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/services/customer/prune_touchbase.rb', line 9

def process(**options)
  logger.debug("Cancelling TOUCHBASE for accounts out of watch")
  activities = Activity.where(activity_type_id: ActivityTypeConstants::TOUCHBASE_ID)
                       .open_activities
                       .joins(:customer)
                       .where(Customer[:watch].in([Customer.watches[:not_watched_auto], Customer.watches[:not_watched_forced]]))
  activities = activities.where(Customer[:primary_sales_rep_id].eq(options[:primary_sales_rep_id])) if options[:primary_sales_rep_id].present?
  activities = activities.where(customer_id: options[:customer_ids]) if options[:customer_ids].present?
  activities = activities.where(party_id: options[:party_ids]) if options[:party_ids].present?
  activities = activities.limit(options[:limit]) if options[:limit]
  activities_processed = activities.size
  logger.debug("Found activities to cancel", count: activities_processed)
  activities.find_each do |activity|
    logger.debug("Cancelling activity", activity_id: activity.id)
    activity.cancel unless options[:dry_run]
  end
  Result.new(success: true, activities_removed: activities_processed)
end