Browse Source

chore: lint

cldc-1888-bulk-upload-duplicate-log-validation
Sam Seed 2 years ago
parent
commit
d869dce24b
  1. 4
      app/mailers/bulk_upload_mailer.rb
  2. 6
      app/services/bulk_upload/lettings/row_parser.rb
  3. 4
      app/services/bulk_upload/lettings/validator.rb
  4. 5
      app/services/bulk_upload/processor.rb

4
app/mailers/bulk_upload_mailer.rb

@ -64,10 +64,10 @@ class BulkUploadMailer < NotifyMailer
correct_and_reupload_description = "Please correct your data export and upload again." correct_and_reupload_description = "Please correct your data export and upload again."
if errors.size == 0 if errors.size.zero?
error_description = correct_and_reupload_description error_description = correct_and_reupload_description
else else
error_description = "We noticed the following issues with your upload:\n\n" #{"s" if errors.size > 1} error_description = "We noticed the following issues with your upload:\n\n" # {"s" if errors.size > 1}
errors.each { |error| error_description << "- #{error}\n" } errors.each { |error| error_description << "- #{error}\n" }
error_description << "\n" error_description << "\n"
end end

6
app/services/bulk_upload/lettings/row_parser.rb

@ -182,7 +182,7 @@ class BulkUpload::Lettings::RowParser
end end
def log_already_exists? def log_already_exists?
fields_for_duplicity_check = %w( fields_for_duplicity_check = %w[
startdate startdate
postcode_full postcode_full
brent brent
@ -194,9 +194,9 @@ class BulkUpload::Lettings::RowParser
sex1 sex1
ecstat1 ecstat1
ethnic ethnic
) ]
LettingsLog.exists?(Hash[fields_for_duplicity_check.collect { |field| [field, log[field]] }]) LettingsLog.exists?(fields_for_duplicity_check.index_with { |field| log[field] })
end end
private private

4
app/services/bulk_upload/lettings/validator.rb

@ -204,14 +204,14 @@ class BulkUpload::Lettings::Validator
end end
def any_logs_already_exist? def any_logs_already_exist?
row_parsers.any? { |row_parser| row_parser.log_already_exists? } row_parsers.any?(&:log_already_exists?)
end end
def any_logs_invalid? def any_logs_invalid?
row_parsers.any? { |row_parser| row_parser.log.invalid? } row_parsers.any? { |row_parser| row_parser.log.invalid? }
end end
private private
def csv_parser def csv_parser
@csv_parser ||= BulkUpload::Lettings::CsvParser.new(path:) @csv_parser ||= BulkUpload::Lettings::CsvParser.new(path:)

5
app/services/bulk_upload/processor.rb

@ -21,10 +21,9 @@ class BulkUpload::Processor
validator.any_setup_sections_incomplete?, validator.any_setup_sections_incomplete?,
validator.over_column_error_threshold?, validator.over_column_error_threshold?,
validator.any_logs_already_exist?, validator.any_logs_already_exist?,
validator.any_logs_invalid? validator.any_logs_invalid?,
) )
end end
rescue StandardError => e rescue StandardError => e
Sentry.capture_exception(e) Sentry.capture_exception(e)
send_failure_mail send_failure_mail
@ -45,7 +44,7 @@ private
over_column_error_threshold, over_column_error_threshold,
any_logs_already_exist, any_logs_already_exist,
any_logs_invalid, any_logs_invalid,
bulk_upload: bulk_upload:,
).deliver_later ).deliver_later
end end

Loading…
Cancel
Save