2021-05-04 14:10:03 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module BulkImports
|
|
|
|
class ExportService
|
2021-05-12 05:10:19 -04:00
|
|
|
def initialize(portable:, user:)
|
|
|
|
@portable = portable
|
2021-05-04 14:10:03 -04:00
|
|
|
@current_user = user
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2021-05-12 05:10:19 -04:00
|
|
|
FileTransfer.config_for(portable).portable_relations.each do |relation|
|
|
|
|
RelationExportWorker.perform_async(current_user.id, portable.id, portable.class.name, relation)
|
2021-05-04 14:10:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
ServiceResponse.success
|
|
|
|
rescue StandardError => e
|
|
|
|
ServiceResponse.error(
|
|
|
|
message: e.class,
|
|
|
|
http_status: :unprocessable_entity
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-05-12 05:10:19 -04:00
|
|
|
attr_reader :portable, :current_user
|
2021-05-04 14:10:03 -04:00
|
|
|
end
|
|
|
|
end
|