Browse Source

refactor: splut out 'log already exists?' logic into dedicated method

cldc-1888-bulk-upload-duplicate-log-validation
Sam Seed 2 years ago
parent
commit
9f88a8570d
  1. 36
      app/services/bulk_upload/lettings/row_parser.rb

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

@ -294,23 +294,9 @@ private
end
def validate_if_log_already_exists
field_mappings = {
"startdate" => startdate,
"postcode_full" => postcode_full,
"brent" => brent,
"scharge" => scharge,
"pscharge" => pscharge,
"supcharg" => supcharg,
"tenancycode" => field_7,
"age1" => field_12,
"sex1" => field_20,
"ecstat1" => field_35,
"ethnic" => field_43,
}
duplicate_log_exists = LettingsLog.where(field_mappings).present?
if duplicate_log_exists
if log_already_exists?
error_message = "This is a duplicate log"
errors.add(:field_96, error_message) # startdate
errors.add(:field_97, error_message) # startdate
errors.add(:field_98, error_message) # startdate
@ -328,6 +314,24 @@ private
end
end
def log_already_exists?
field_mappings = {
"startdate" => startdate,
"postcode_full" => postcode_full,
"brent" => brent,
"scharge" => scharge,
"pscharge" => pscharge,
"supcharg" => supcharg,
"tenancycode" => field_7,
"age1" => field_12,
"sex1" => field_20,
"ecstat1" => field_35,
"ethnic" => field_43,
}
LettingsLog.where(field_mappings).present?
end
def field_mapping_for_errors
{
lettype: [:field_1],

Loading…
Cancel
Save