Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use enums with graphene #399

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions children/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
DjangoFilterAndOffsetConnectionField,
set_obj_languages_spoken_at_home,
)
from common.utils import login_required, map_enums_to_values_in_kwargs, update_object
from common.utils import login_required, safe_test_and_get_enum_value, update_object
from events.models import Event, Occurrence
from kukkuu.exceptions import (
ApiUsageError,
Expand Down Expand Up @@ -393,7 +393,6 @@ class Input:
@classmethod
@login_required
@transaction.atomic
@map_enums_to_values_in_kwargs
def mutate_and_get_payload(cls, root, info, **kwargs):
user = info.context.user
if hasattr(user, "guardian"):
Expand Down Expand Up @@ -423,7 +422,7 @@ def mutate_and_get_payload(cls, root, info, **kwargs):
first_name=guardian_data["first_name"],
last_name=guardian_data["last_name"],
phone_number=guardian_data.get("phone_number", ""),
language=guardian_data["language"],
language=safe_test_and_get_enum_value(guardian_data["language"]),
email=guardian_data["email"],
has_accepted_communication=guardian_data.get(
"has_accepted_communication", False
Expand All @@ -443,7 +442,9 @@ def mutate_and_get_payload(cls, root, info, **kwargs):

child = Child.objects.create(**child_data)
Relationship.objects.create(
type=relationship_data.get("type"), child=child, guardian=guardian
type=safe_test_and_get_enum_value(relationship_data.get("type")),
child=child,
guardian=guardian,
)
set_obj_languages_spoken_at_home(info, child, languages)

Expand Down Expand Up @@ -481,7 +482,6 @@ class Input(BaseNewChildInput):
@classmethod
@login_required
@transaction.atomic
@map_enums_to_values_in_kwargs
def mutate_and_get_payload(cls, root, info, **kwargs):
user = info.context.user
if not hasattr(user, "guardian"):
Expand All @@ -503,7 +503,9 @@ def mutate_and_get_payload(cls, root, info, **kwargs):

child = Child.objects.create(**kwargs)
Relationship.objects.create(
type=relationship_data.get("type"), child=child, guardian=user.guardian
type=safe_test_and_get_enum_value(relationship_data.get("type")),
child=child,
guardian=user.guardian,
)
set_obj_languages_spoken_at_home(info, child, languages)

Expand All @@ -525,7 +527,6 @@ class Input(BaseUpdateChildInput):
@classmethod
@login_required
@transaction.atomic
@map_enums_to_values_in_kwargs
def mutate_and_get_payload(cls, root, info, **kwargs):
validate_child_data(kwargs)
user = info.context.user
Expand Down Expand Up @@ -563,7 +564,6 @@ class Input:
@classmethod
@login_required
@transaction.atomic
@map_enums_to_values_in_kwargs
def mutate_and_get_payload(cls, root, info, **kwargs):
user = info.context.user

Expand Down Expand Up @@ -592,7 +592,6 @@ class Input:
@classmethod
@login_required
@transaction.atomic
@map_enums_to_values_in_kwargs
def mutate_and_get_payload(cls, root, info, **kwargs):
user = info.context.user
child_global_id = kwargs.pop("child_id")
Expand Down
Loading