Class: PartyActivityCreator
- Inherits:
-
Object
- Object
- PartyActivityCreator
- Defined in:
- app/services/party_activity_creator.rb
Overview
Creates an Activity for a Party (Customer or Contact) for a given task type.
Behavior preserved from the legacy Party#create_activity helper:
- returns nil if the party has no customer (e.g. orphaned contact)
- returns nil if the task type is unknown
- by default, dedupes by skipping when an open activity of the same type
already exists on the customer (override with skip_if_exists: false) - resolves the assigned resource via the supplied option, the activity
type's own assignment logic, or the customer's sales manager - rolls the target date to the next working day for the assignee
Flat name (not Activity::Creator) because Activity is an AR model and
Zeitwerk would otherwise create a top-level Activity module.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(party, task_type, **options) ⇒ PartyActivityCreator
constructor
A new instance of PartyActivityCreator.
Constructor Details
#initialize(party, task_type, **options) ⇒ PartyActivityCreator
Returns a new instance of PartyActivityCreator.
21 22 23 24 25 |
# File 'app/services/party_activity_creator.rb', line 21 def initialize(party, task_type, **) @party = party @task_type = task_type @options = end |
Class Method Details
.call(party, task_type, **options) ⇒ Object
17 18 19 |
# File 'app/services/party_activity_creator.rb', line 17 def self.call(party, task_type, **) new(party, task_type, **).call end |
Instance Method Details
#call ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'app/services/party_activity_creator.rb', line 27 def call return unless customer_present? activity_type = ActivityType.find_by(task_type: @task_type) return unless activity_type return if duplicate_open_activity?(activity_type) persist_activity!(activity_type) end |