Skip to content

Commit

Permalink
feat(admissions): Applicant phone number field validation on patch
Browse files Browse the repository at this point in the history
  • Loading branch information
alexaor committed Aug 4, 2022
1 parent 46b7240 commit 66b2d2f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion admissions/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
get_admission_final_applicant_qs,
get_applicant_offered_position,
)
from django.core.exceptions import SuspiciousOperation
from django.core.exceptions import SuspiciousOperation, ValidationError
from django.utils import timezone
from admissions.models import (
Applicant,
Expand Down Expand Up @@ -828,6 +828,22 @@ class PatchApplicantMutation(DjangoPatchMutation):
class Meta:
model = Applicant

def validate_phone(root, info, value, input, ex1, ex2):
print(ex1, ex2)
if value == "":
raise ValidationError("Phone number cannot be empty")

user_phone_check = User.objects.filter(phone=value).exists()
if user_phone_check:
raise ValidationError(
"This phone number is already in use by another user."
)
applicant_phone_check = Applicant.objects.filter(phone=value).exists()
if applicant_phone_check:
raise ValidationError(
"This phone number is already in use by another applicant."
)


class DeleteApplicantMutation(DjangoDeleteMutation):
class Meta:
Expand Down

0 comments on commit 66b2d2f

Please sign in to comment.