Browse Source

Fix address options for address search question

CLDC-3787-Autocomplete-address-search
Manny Dinssa 4 days ago
parent
commit
ad45f17ab4
  1. 1
      app/models/form/lettings/questions/address_search.rb
  2. 1
      app/models/form/sales/questions/address_search.rb
  3. 21
      app/models/log.rb

1
app/models/form/lettings/questions/address_search.rb

@ -19,7 +19,6 @@ class Form::Lettings::Questions::AddressSearch < ::Form::Question
answer_opts[log.address_options[i][:uprn]] = { "value" => log.address_options[i][:address] }
end
answer_opts["divider"] = { "value" => true }
answer_opts
end

1
app/models/form/sales/questions/address_search.rb

@ -19,7 +19,6 @@ class Form::Sales::Questions::AddressSearch < ::Form::Question
answer_opts[log.address_options[i][:uprn]] = { "value" => log.address_options[i][:address] }
end
answer_opts["divider"] = { "value" => true }
answer_opts
end

21
app/models/log.rb

@ -126,19 +126,27 @@ class Log < ApplicationRecord
end
def address_options
search_query = address_search.presence || address_string
return @address_options if @address_options && @last_searched_address_string == search_query
if address_search.present?
service = UprnClient.new(address_search)
service.call
if service.result.blank? || service.error.present?
@address_options = []
return @address_options
end
search_query = address_search.presence || address_string
return if search_query.blank?
presenter = AddressDataPresenter.new(service.result)
@address_options = [{ address: presenter.address, uprn: presenter.uprn }]
else
return @address_options if @address_options && @last_searched_address_string == address_string
return if address_string.blank?
@last_searched_address_string = search_query
@last_searched_address_string = address_string
service = AddressClient.new(address_string)
service.call
if service.result.blank? || service.error.present?
@address_options = []
return @answer_options
return @address_options
end
address_opts = []
@ -149,6 +157,7 @@ class Log < ApplicationRecord
@address_options = address_opts
end
end
def collection_start_year
return @start_year if @start_year

Loading…
Cancel
Save