-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of | ||
# hitobito_sac_cas and licensed under the Affero General Public License version 3 | ||
# or later. See the COPYING file at the top-level directory or at | ||
# https://github.com/hitobito/hitobito_sac_cas | ||
|
||
class People::DataQualityChecker | ||
ATTRIBUTES_TO_CHECK = %w[email street zip_code town first_name last_name | ||
company_name phone_numbers birthday] | ||
|
||
def initialize(person) | ||
@person = person | ||
|
||
check_invoice_recipient if @person.sac_membership_invoice? | ||
check_stammsektion if @person.roles.exists?(type: SacCas::STAMMSEKTION_ROLES) | ||
|
||
if @person.company? | ||
check("warning", "company_name", "ist leer", invalid: @person.company_name.blank?) | ||
else | ||
check("error", "first_name", "ist leer", invalid: @person.first_name.blank?) | ||
check("error", "last_name", "ist leer", invalid: @person.last_name.blank?) | ||
end | ||
end | ||
|
||
private | ||
|
||
def check_invoice_recipient | ||
check("error", "street", "ist leer", invalid: @person.street.blank?) | ||
check("error", "zip_code", "ist leer", invalid: @person.zip_code.blank?) | ||
check("error", "town", "ist leer", invalid: @person.town.blank?) | ||
check("warning", "email", "ist leer", invalid: @person.email.blank?) | ||
check("warning", "phone_numbers", "sind leer", invalid: @person.phone_numbers.blank?) | ||
end | ||
|
||
def check_stammsektion | ||
join_date = @person.roles.find_by(type: SacCas::STAMMSEKTION_ROLES).created_at | ||
|
||
check("error", "birthday", "ist leer", invalid: @person.birthday.blank?) | ||
check("warning", "birthday", "liegt weniger als 6 Jahre vor dem SAC-Eintritt", | ||
invalid: @person.birthday.present? && (@person.birthday > join_date - 6.years)) | ||
end | ||
|
||
def check(severity, attr, key, invalid: false) | ||
if invalid | ||
issue = @person.data_quality_issues.new(severity: severity, attr: attr, key: key) | ||
issue.save! if issue.valid? | ||
else | ||
@person.data_quality_issues.find_by(severity: severity, attr: attr, key: key)&.destroy! | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters