Skip to content

Commit

Permalink
[#197] Handle report error if school_information not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
wayangalihpratama committed Oct 8, 2024
1 parent b580473 commit 14c946d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
22 changes: 20 additions & 2 deletions backend/seeder/data_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
19 changes: 18 additions & 1 deletion backend/seeder/datapoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions backend/utils/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 14c946d

Please sign in to comment.