mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-07-17 20:55:50 +00:00
refactor(verification): enhance error handling and response structure in user verification process 🔨
This commit is contained in:
17
api/views.py
17
api/views.py
@ -406,23 +406,22 @@ class UserVerifyAPIView(StaffEditorPermissionMixin, generics.UpdateAPIView):
|
||||
{"message": "You are not authorized to update this user."},
|
||||
status=status.HTTP_403_FORBIDDEN,
|
||||
)
|
||||
if user.verified:
|
||||
return Response(
|
||||
{"message": "User is already verified."},
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
)
|
||||
serializer = self.get_serializer(user, data=request.data, partial=True)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
result = check_person_api_verification(user_data=user, id_card=user.id_card)
|
||||
if not result["ok"]:
|
||||
return Response(
|
||||
{
|
||||
"message": "User verification failed. Please check the api user details.",
|
||||
"mismatch_fields": result["mismatch_fields"],
|
||||
},
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
result,
|
||||
status=status.HTTP_404_NOT_FOUND,
|
||||
)
|
||||
if result["mismatch_fields"]:
|
||||
return Response(
|
||||
{
|
||||
"message": "User verification failed due to mismatched fields.",
|
||||
"mismatch_fields": result["mismatch_fields"],
|
||||
},
|
||||
result,
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
)
|
||||
user.verified = True
|
||||
|
Reference in New Issue
Block a user