From 14c946d32764b730f34910a6579ff8c668e933df Mon Sep 17 00:00:00 2001 From: wayangalihpratama Date: Tue, 8 Oct 2024 13:55:38 +0800 Subject: [PATCH] [#197] Handle report error if school_information not defined --- backend/seeder/data_sync.py | 22 ++++++++++++++++++++-- backend/seeder/datapoint.py | 19 ++++++++++++++++++- backend/utils/i18n.py | 1 + 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/backend/seeder/data_sync.py b/backend/seeder/data_sync.py index b91411e..a04b3f8 100644 --- a/backend/seeder/data_sync.py +++ b/backend/seeder/data_sync.py @@ -121,7 +121,7 @@ def data_sync(token: dict, session: Session, sync_data: dict): form = crud_form.get_form_by_id(session=session, id=fi.get("formId")) if not form: continue - + form_id = form.id datapoint_id = fi.get("dataPointId") data_id = fi.get("id") answers = [] @@ -162,6 +162,7 @@ def data_sync(token: dict, session: Session, sync_data: dict): desc = ValidationText.incorrect_monitoring_round.value error.append( { + "form_id": form_id, "instance_id": data_id, "answer": monitoring_answer, "type": desc, @@ -314,19 +315,36 @@ def data_sync(token: dict, session: Session, sync_data: dict): school_information = answer.options # EOL custom + # check if school_information is not defined + if not school_information: + desc = ValidationText.school_information_is_not_defined.value + error.append( + { + "form_id": form_id, + "instance_id": data_id, + "answer": f"NULL - {year_conducted}", + "description": desc, + } + ) + is_error = True + # EOL check if school_information is not defined + # check datapoint with same school and monitoring round check_same_school_and_monitoring = None - if not updated_data and year_conducted: + if not updated_data and year_conducted and school_information: check_same_school_and_monitoring = crud_data.get_data_by_school( session=session, schools=school_information, year_conducted=year_conducted, ) if check_same_school_and_monitoring: + prev_instance = check_same_school_and_monitoring.id school_answer = "|".join(school_information) desc = ValidationText.school_monitoring_exist.value + desc = f"{desc} - prev instance_id: {prev_instance}" error.append( { + "form_id": form_id, "instance_id": data_id, "answer": f"{school_answer} - {year_conducted}", "description": desc, diff --git a/backend/seeder/datapoint.py b/backend/seeder/datapoint.py index e24262f..12ffd78 100644 --- a/backend/seeder/datapoint.py +++ b/backend/seeder/datapoint.py @@ -81,6 +81,7 @@ def seed_datapoint(session: Session, token: dict, data: dict, form: Form): desc = ValidationText.incorrect_monitoring_round.value error.append( { + "form_id": form_id, "instance_id": data_id, "answer": monitoring_answer, "description": desc, @@ -149,17 +150,33 @@ def seed_datapoint(session: Session, token: dict, data: dict, form: Form): school_information = answer.options # EOL custom + # check if school_information is not defined + if not school_information: + desc = ValidationText.school_information_is_not_defined.value + error.append( + { + "form_id": form_id, + "instance_id": data_id, + "answer": f"NULL - {year_conducted}", + "description": desc, + } + ) + is_error = True + # EOL check if school_information is not defined + # check datapoint with same school and monitoring round check_same_school_and_monitoring = None - if year_conducted: + if year_conducted and school_information: check_same_school_and_monitoring = crud_data.get_data_by_school( session=session, schools=school_information, year_conducted=year_conducted, ) if check_same_school_and_monitoring: + prev_instance = check_same_school_and_monitoring.id school_answer = "|".join(school_information) desc = ValidationText.school_monitoring_exist.value + desc = f"{desc} - prev instance_id: {prev_instance}" error.append( { "form_id": form_id, diff --git a/backend/utils/i18n.py b/backend/utils/i18n.py index 60547e3..1060cec 100644 --- a/backend/utils/i18n.py +++ b/backend/utils/i18n.py @@ -4,6 +4,7 @@ class ValidationText(enum.Enum): incorrect_monitoring_round = "incorrect monitoring round" school_monitoring_exist = "school in same monitoring round already exist" + school_information_is_not_defined = "scool information is not defined" class EmailText(enum.Enum):