Browse Source

feat: store address input separately

pull/2278/head
natdeanlewissoftwire 2 years ago
parent
commit
5997403fae
  1. 2
      app/models/form/lettings/pages/address_selection.rb
  2. 2
      app/models/form/lettings/questions/address_line1_for_address_matcher.rb
  3. 2
      app/models/form/lettings/questions/postcode_for_address_matcher.rb
  4. 12
      app/models/log.rb
  5. 14
      db/schema.rb

2
app/models/form/lettings/pages/address_selection.rb

@ -12,7 +12,7 @@ class Form::Lettings::Pages::AddressSelection < ::Form::Page
end
def routed_to?(log, _current_user = nil)
log.uprn_known.present? && log.uprn_known.zero? && log.address_line1.present? && log.postcode_full.present?
log.uprn_known.present? && log.uprn_known.zero? && log.address_line1_input.present? && log.postcode_full_input.present?
end
def skip_text

2
app/models/form/lettings/questions/address_line1_for_address_matcher.rb

@ -1,7 +1,7 @@
class Form::Lettings::Questions::AddressLine1ForAddressMatcher < ::Form::Question
def initialize(id, hsh, page)
super
@id = "address_line1"
@id = "address_line1_input"
@header = "Address line 1"
@error_label = "Address line 1"
@type = "text"

2
app/models/form/lettings/questions/postcode_for_address_matcher.rb

@ -1,7 +1,7 @@
class Form::Lettings::Questions::PostcodeForAddressMatcher < ::Form::Question
def initialize(id, hsh, page)
super
@id = "postcode_full"
@id = "postcode_full_input"
@header = "Postcode"
@type = "text"
@width = 5

12
app/models/log.rb

@ -77,12 +77,12 @@ class Log < ApplicationRecord
end
def process_address_change!
if [address_selection, address_line1, postcode_full].all?(&:present?)
address_string = "#{address_line1}, , , #{postcode_full}"
if [address_selection, address_line1_input, postcode_full_input].all?(&:present?)
address_string = "#{address_line1_input}, , , #{postcode_full_input}"
service = AddressClient.new(address_string)
service.call
return errors.add(:address_line1, :address_error, message: service.error) if service.error.present?
return errors.add(:address_line1_input, :address_error, message: service.error) if service.error.present?
if address_selection.between?(0, 9)
presenter = AddressDataPresenter.new(service.result[address_selection])
@ -109,12 +109,12 @@ class Log < ApplicationRecord
end
def address_options
if [address_line1, postcode_full].all?(&:present?)
address_string = "#{address_line1}, , , #{postcode_full}"
if [address_line1_input, postcode_full_input].all?(&:present?)
address_string = "#{address_line1_input}, , , #{postcode_full_input}"
service = AddressClient.new(address_string)
service.call
return errors.add(:address_line1, :address_error, message: service.error) if service.error.present?
return errors.add(:address_line1_input, :address_error, message: service.error) if service.error.present?
address_options = []
service.result.first(10).each do |result|

14
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2024_02_27_163853) do
ActiveRecord::Schema[7.0].define(version: 2024_03_04_103216) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -193,14 +193,14 @@ ActiveRecord::Schema[7.0].define(version: 2024_02_27_163853) do
t.integer "hb"
t.integer "hbrentshortfall"
t.integer "property_relet"
t.datetime "mrcdate"
t.datetime "mrcdate", precision: nil
t.integer "incref"
t.datetime "startdate"
t.datetime "startdate", precision: nil
t.integer "armedforces"
t.integer "first_time_property_let_as_social_housing"
t.integer "unitletas"
t.integer "builtype"
t.datetime "voiddate"
t.datetime "voiddate", precision: nil
t.bigint "owning_organisation_id"
t.bigint "managing_organisation_id"
t.integer "renttype"
@ -309,6 +309,8 @@ ActiveRecord::Schema[7.0].define(version: 2024_02_27_163853) do
t.integer "reasonother_value_check"
t.integer "accessible_register"
t.integer "address_selection"
t.string "address_line1_input"
t.string "postcode_full_input"
t.index ["bulk_upload_id"], name: "index_lettings_logs_on_bulk_upload_id"
t.index ["created_by_id"], name: "index_lettings_logs_on_created_by_id"
t.index ["location_id"], name: "index_lettings_logs_on_location_id"
@ -713,8 +715,8 @@ ActiveRecord::Schema[7.0].define(version: 2024_02_27_163853) do
t.string "name"
t.bigint "organisation_id"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.datetime "current_sign_in_at", precision: nil
t.datetime "last_sign_in_at", precision: nil
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.integer "role"

Loading…
Cancel
Save