Browse Source

feat: validate confirmed

pull/1034/head
natdeanlewissoftwire 4 years ago
parent
commit
2bb916508d
  1. 3
      app/controllers/locations_controller.rb
  2. 11
      app/models/location.rb

3
app/controllers/locations_controller.rb

@ -145,8 +145,7 @@ class LocationsController < ApplicationController
def check_answers; end
def update_check_answers
@location.confirmed = true
@location.save!
@location.confirmed!
flash[:notice] = "#{@location.postcode} #{@location.startdate < Time.zone.now ? 'has been' : 'will be'} added to this scheme"
redirect_to scheme_locations_path(@scheme)
end

11
app/models/location.rb

@ -7,6 +7,7 @@ class Location < ApplicationRecord
validates :type_of_unit, on: :type_of_unit, presence: { message: I18n.t("validations.location.type_of_unit") }
validates :mobility_type, on: :mobility_type, presence: { message: I18n.t("validations.location.mobility_standards") }
validate :validate_startdate, on: :startdate
validate :validate_confirmed
belongs_to :scheme
has_many :lettings_logs, class_name: "LettingsLog"
has_many :location_deactivation_periods, class_name: "LocationDeactivationPeriod"
@ -428,10 +429,20 @@ class Location < ApplicationRecord
end
end
def validate_confirmed
if confirmed == true && incomplete?
self.confirmed = false
end
end
def incomplete?
[postcode, name, location_admin_district, location_code, units, type_of_unit, mobility_type, startdate].any?(&:blank?)
end
def confirmed!
update!(confirmed: true)
end
private
PIO = PostcodeService.new

Loading…
Cancel
Save