2021-01-03 14:25:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class BulkUpdateIntegrationService
|
|
|
|
def initialize(integration, batch)
|
|
|
|
@integration = integration
|
|
|
|
@batch = batch
|
|
|
|
end
|
|
|
|
|
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
|
|
|
def execute
|
2021-06-08 01:23:25 +05:30
|
|
|
Integration.transaction do
|
|
|
|
Integration.where(id: batch.select(:id)).update_all(service_hash)
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def service_hash
|
2021-01-29 00:20:46 +05:30
|
|
|
integration.to_service_hash.tap { |json| json['inherit_from_id'] = integration.inherit_from_id || integration.id }
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def data_fields_hash
|
|
|
|
integration.to_data_fields_hash
|
|
|
|
end
|
|
|
|
end
|