From 67eaca0d87d965cf6ec7d6bc9d0a0b3ab7fbf3bf Mon Sep 17 00:00:00 2001 From: Chris <76159444+hunchr@users.noreply.github.com> Date: Thu, 22 Aug 2024 07:18:09 +0000 Subject: [PATCH] Update `Person::DataQualityIssue` --- app/models/person/data_quality_issue.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/app/models/person/data_quality_issue.rb b/app/models/person/data_quality_issue.rb index fae7cd6c0..5419ebd06 100644 --- a/app/models/person/data_quality_issue.rb +++ b/app/models/person/data_quality_issue.rb @@ -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), @@ -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