Skip to content

Commit

Permalink
Add ID to validation_issue
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljames-dj committed Jan 3, 2025
1 parent f86e5d0 commit af0c4cd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/results_validators/persons_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ def self.dob_validations(dob, competition_id = nil, name = nil)

# Check if DOB is January 1
if dob.month == 1 && dob.day == 1
validation_issues << ValidationWarning.new(:persons, competition_id, DOB_0101_WARNING, name: name)
validation_issues << ValidationWarning.new(ValidationIssue::VALIDATION_TYPES[:dob_jan_one], :persons, competition_id, DOB_0101_WARNING, name: name)
end

# Check if DOB is very young, competitor less than 3 years old are extremely rare, so we'd better check these birthdate are correct.
if dob.year >= Time.now.year - 3
validation_issues << ValidationWarning.new(:persons, competition_id, VERY_YOUNG_PERSON_WARNING, name: name)
validation_issues << ValidationWarning.new(ValidationIssue::VALIDATION_TYPES[:dob_too_young], :persons, competition_id, VERY_YOUNG_PERSON_WARNING, name: name)
end

# Check if DOB is not so young
if dob.year <= Time.now.year - 100
validation_issues << ValidationWarning.new(:persons, competition_id, NOT_SO_YOUNG_PERSON_WARNING, name: name)
validation_issues << ValidationWarning.new(ValidationIssue::VALIDATION_TYPES[:dob_too_old], :persons, competition_id, NOT_SO_YOUNG_PERSON_WARNING, name: name)
end

validation_issues
Expand Down
15 changes: 14 additions & 1 deletion lib/results_validators/validation_issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,21 @@

module ResultsValidators
class ValidationIssue
# Maintain the list in alphabetical order. This is to easily identify if a duplicate is added.
# Since this is not rails model, we need to manually maintain the uniqueness of the keys.
VALIDATION_TYPES_KEYS = [
:dob_jan_one,
:dob_too_old,
:dob_too_young,
].freeze

VALIDATION_TYPES = VALIDATION_TYPES_KEYS.each_with_object({}) do |key, hash|
hash[key] = key.to_s
end.freeze

attr_reader :kind, :competition_id
def initialize(kind, competition_id, message, **message_args)
def initialize(id, kind, competition_id, message, **message_args)
@id = id
@message = message
@kind = kind
@args = message_args
Expand Down

0 comments on commit af0c4cd

Please sign in to comment.