7
8
9
10
11
12
13
14
15
16
|
# File 'app/services/rails_drips/complete_enrollment.rb', line 7
def self.call(enrollment:)
enrollment.with_lock do
return Result.new(status: :not_active, enrollment: enrollment) unless enrollment.active?
return Result.new(status: :pending, enrollment: enrollment) if enrollment.deliveries.where(status: BLOCKING_STATUSES).exists?
enrollment.complete!
RecordEvent.call(enrollment: enrollment, event_type: "completed")
Result.new(status: :completed, enrollment: enrollment)
end
end
|