Skip to content

Commit

Permalink
Update Person::DataQualityIssue
Browse files Browse the repository at this point in the history
  • Loading branch information
hunchr committed Aug 22, 2024
1 parent 1e68646 commit 67eaca0
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions app/models/person/data_quality_issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,14 @@
# index_person_data_quality_issues_on_person_and_attribute_and_key (key) UNIQUE

class Person::DataQualityIssue < ApplicationRecord
VALID_ATTRIBUTES = Person.column_names + ["phone_numbers"]

belongs_to :person

enum severity: {info: 1, warning: 2, error: 3}

validate :person_attribute_exists
validate :person_attribute_to_check
validates :attr, :severity, presence: true
validates :key, uniqueness: {scope: %i[person_id attr]}, presence: true

def severity=(value)
super(self.class.severities.keys.index(value.to_s)&.next)
end

def message
I18n.t("activemodel.errors.models.person.data_quality_issue.message",
attr: Person.human_attribute_name(attr),
Expand All @@ -47,7 +41,9 @@ def message

private

def person_attribute_exists
errors.add(:attr, :invalid) unless VALID_ATTRIBUTES.include?(attr)
def person_attribute_to_check
return if People::DataQualityChecker::ATTRIBUTES_TO_CHECK.include?(attr)

errors.add(:attr, :invalid)
end
end

0 comments on commit 67eaca0

Please sign in to comment.