You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.4 KiB
31 lines
1.4 KiB
class EmailMissingAddressesCsvJob < ApplicationJob |
|
queue_as :default |
|
|
|
BYTE_ORDER_MARK = "\uFEFF".freeze # Required to ensure Excel always reads CSV as UTF-8 |
|
|
|
def perform(user_ids, organisation, log_type, template_type) |
|
csv_service = Csv::MissingAddressesCsvService.new(organisation:) |
|
case log_type |
|
when "lettings" |
|
csv_string = template_type == "town-or-city" ? csv_service.create_missing_lettings_town_or_city_csv : csv_service.create_missing_lettings_addresses_csv |
|
filename = "#{['missing-lettings-logs', template_type, organisation.name, Time.zone.now].compact.join('-')}.csv" |
|
email_method = :send_missing_lettings_addresses_csv_download_mail |
|
when "sales" |
|
csv_string = template_type == "town-or-city" ? csv_service.create_missing_sales_town_or_city_csv : csv_service.create_missing_sales_addresses_csv |
|
filename = "#{['missing-sales-logs', template_type, organisation.name, Time.zone.now].compact.join('-')}.csv" |
|
email_method = :send_missing_sales_addresses_csv_download_mail |
|
end |
|
|
|
storage_service = Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["CSV_DOWNLOAD_PAAS_INSTANCE"]) |
|
storage_service.write_file(filename, BYTE_ORDER_MARK + csv_string) |
|
|
|
url = storage_service.get_presigned_url(filename, nil) |
|
|
|
user_ids.each do |id| |
|
user = User.find(id) |
|
next if user.blank? |
|
|
|
CsvDownloadMailer.new.send(email_method, user, url, template_type) |
|
end |
|
end |
|
end
|
|
|