blob: bb9bddb59671b5b6d0d3a9c157116550aad3da77 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# frozen_string_literal: true
class BulkUpdateIntegrationService
def initialize(integration, batch)
@integration = integration
@batch = batch
end
# rubocop: disable CodeReuse/ActiveRecord
def execute
Service.transaction do
batch.update_all(service_hash)
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
integration.to_service_hash.tap { |json| json['inherit_from_id'] = integration.inherit_from_id || integration.id }
end
def data_fields_hash
integration.to_data_fields_hash
end
end
|