Skip to content

Commit

Permalink
Added name argument to validators for ticket validations (thewca#10572)
Browse files Browse the repository at this point in the history
* Added name argument to validators for ticket validations

* Review changes
  • Loading branch information
danieljames-dj authored Jan 13, 2025
1 parent da1a399 commit 12c33cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion app/controllers/tickets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def edit_person_validators
ticket.metadata.tickets_edit_person_fields.each do |edit_person_field|
case edit_person_field[:field_name]
when TicketsEditPersonField.field_names[:dob]
dob_validation_issues = ResultsValidators::PersonsValidator.dob_validations(Date.parse(edit_person_field[:new_value]))
dob_to_validate = Date.parse(edit_person_field[:new_value])
dob_validation_issues = ResultsValidators::PersonsValidator.dob_validations(dob_to_validate, nil, name: ticket.metadata.wca_id)
end
end

Expand Down
10 changes: 5 additions & 5 deletions lib/results_validators/persons_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@ def include_persons?
true
end

def self.dob_validations(dob, competition_id = nil, name = nil)
def self.dob_validations(dob, competition_id = nil, **message_args)
validation_issues = []

# 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(:persons, competition_id, DOB_0101_WARNING, **message_args)
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(:persons, competition_id, VERY_YOUNG_PERSON_WARNING, **message_args)
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(:persons, competition_id, NOT_SO_YOUNG_PERSON_WARNING, **message_args)
end

validation_issues
Expand Down Expand Up @@ -101,7 +101,7 @@ def run_validation(validator_data)
name: p.name)
end

PersonsValidator.dob_validations(p.dob, competition.id, p.name).each do |validation|
PersonsValidator.dob_validations(p.dob, competition.id, name: p.name).each do |validation|
if validation.is_a?(ValidationError)
@errors << validation
elsif validation.is_a?(ValidationWarning)
Expand Down

0 comments on commit 12c33cb

Please sign in to comment.