Browse Source

update interface of relevant methods

EmailCsvJob, LettingsLog.to_csv and LettingsLogCsvService consume codes_only flag
pull/1268/head
Arthur Campbell 3 years ago
parent
commit
c4a7d5640e
  1. 4
      app/jobs/email_csv_job.rb
  2. 4
      app/models/lettings_log.rb
  3. 4
      app/services/csv/lettings_log_csv_service.rb

4
app/jobs/email_csv_job.rb

@ -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)

4
app/models/lettings_log.rb

@ -444,8 +444,8 @@ class LettingsLog < Log
location&.id
end
def self.to_csv(user = nil)
Csv::LettingsLogCsvService.new(user).to_csv
def self.to_csv(user = nil, is_codes_only_export:)
Csv::LettingsLogCsvService.new(user).to_csv(is_codes_only_export:)
end
def beds_for_la_rent_range

4
app/services/csv/lettings_log_csv_service.rb

@ -7,13 +7,13 @@ module Csv
set_csv_attributes
end
def to_csv
def to_csv(is_codes_only_export:)
CSV.generate(headers: true) do |csv|
csv << @attributes
LettingsLog.all.find_each do |record|
csv << @attributes.map do |att|
label_from_value(record, att)
label_from_value(record, att, is_codes_only_export:)
end
end
end

Loading…
Cancel
Save