|
|
@ -1,5 +1,5 @@ |
|
|
|
class Location < ApplicationRecord |
|
|
|
class Location < ApplicationRecord |
|
|
|
validate :validate_postcode |
|
|
|
validate :validate_postcode, :validate_startdate |
|
|
|
validates :units, :type_of_unit, presence: true |
|
|
|
validates :units, :type_of_unit, presence: true |
|
|
|
belongs_to :scheme |
|
|
|
belongs_to :scheme |
|
|
|
|
|
|
|
|
|
|
@ -49,6 +49,13 @@ private |
|
|
|
|
|
|
|
|
|
|
|
PIO = PostcodeService.new |
|
|
|
PIO = PostcodeService.new |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def validate_startdate |
|
|
|
|
|
|
|
unless startdate.nil? || (startdate.is_a?(ActiveSupport::TimeWithZone) && !startdate.year.zero?) |
|
|
|
|
|
|
|
error_message = I18n.t("validations.date.invalid_date") |
|
|
|
|
|
|
|
errors.add :startdate, error_message |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def validate_postcode |
|
|
|
def validate_postcode |
|
|
|
if postcode.nil? || !postcode&.match(POSTCODE_REGEXP) |
|
|
|
if postcode.nil? || !postcode&.match(POSTCODE_REGEXP) |
|
|
|
error_message = I18n.t("validations.postcode") |
|
|
|
error_message = I18n.t("validations.postcode") |
|
|
|