2020-09-29 11:10:08 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class BulkUpdateIntegrationService
|
|
|
|
def initialize(integration, batch)
|
|
|
|
@integration = integration
|
|
|
|
@batch = batch
|
|
|
|
end
|
|
|
|
|
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
|
|
|
def execute
|
2021-05-12 08:10:24 -04:00
|
|
|
Integration.transaction do
|
2021-06-30 02:07:17 -04:00
|
|
|
Integration.where(id: batch.select(:id)).update_all(integration_hash)
|
2020-09-29 11:10:08 -04:00
|
|
|
|
|
|
|
if integration.data_fields_present?
|
|
|
|
integration.data_fields.class.where(service_id: batch.select(:id)).update_all(data_fields_hash)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :integration, :batch
|
|
|
|
|
2021-06-30 02:07:17 -04:00
|
|
|
def integration_hash
|
|
|
|
integration.to_integration_hash.tap { |json| json['inherit_from_id'] = integration.inherit_from_id || integration.id }
|
2020-09-29 11:10:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def data_fields_hash
|
|
|
|
integration.to_data_fields_hash
|
|
|
|
end
|
|
|
|
end
|