|
|
|
|
@ -5,14 +5,14 @@ class EmailCsvJob < ApplicationJob
|
|
|
|
|
|
|
|
|
|
EXPIRATION_TIME = 3.hours.to_i |
|
|
|
|
|
|
|
|
|
def perform(user, search_term = nil, filters = {}, all_orgs = false, organisation = nil) # rubocop:disable Style/OptionalBooleanParameter - sidekiq can't serialise named params |
|
|
|
|
def perform(user, search_term = nil, filters = {}, all_orgs = false, organisation = nil, is_codes_only_export = false) # rubocop:disable Style/OptionalBooleanParameter - sidekiq can't serialise named params |
|
|
|
|
unfiltered_logs = organisation.present? && user.support? ? LettingsLog.where(owning_organisation_id: organisation.id) : user.lettings_logs |
|
|
|
|
filtered_logs = FilterService.filter_logs(unfiltered_logs, search_term, filters, all_orgs, user) |
|
|
|
|
|
|
|
|
|
filename = organisation.present? ? "logs-#{organisation.name}-#{Time.zone.now}.csv" : "logs-#{Time.zone.now}.csv" |
|
|
|
|
|
|
|
|
|
storage_service = Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["CSV_DOWNLOAD_PAAS_INSTANCE"]) |
|
|
|
|
storage_service.write_file(filename, BYTE_ORDER_MARK + filtered_logs.to_csv(user)) |
|
|
|
|
storage_service.write_file(filename, BYTE_ORDER_MARK + filtered_logs.to_csv(user, is_codes_only_export)) |
|
|
|
|
|
|
|
|
|
url = storage_service.get_presigned_url(filename, EXPIRATION_TIME) |
|
|
|
|
|
|
|
|
|
|