diff --git a/api/dashboard/profile/profile_serializer.py b/api/dashboard/profile/profile_serializer.py index 3839a3a8..2a864ba7 100644 --- a/api/dashboard/profile/profile_serializer.py +++ b/api/dashboard/profile/profile_serializer.py @@ -434,8 +434,6 @@ def create_karma_activity_log(task_hashtag, karma_value): return super().update(instance, validated_data) class UserTermSerializer(serializers.ModelSerializer): - is_userterms_approved = serializers.SerializerMethodField() - class Meta: model = UserSettings @@ -443,7 +441,7 @@ class Meta: "is_userterms_approved", "user", ] - def get_userterm(self, instance, validated_data): + def update(self, instance, validated_data): instance.is_userterms_approved = validated_data.get('is_userterms_approved', instance.is_userterms_approved) instance.save() return instance diff --git a/api/dashboard/profile/profile_view.py b/api/dashboard/profile/profile_view.py index 78682db4..817a2930 100644 --- a/api/dashboard/profile/profile_view.py +++ b/api/dashboard/profile/profile_view.py @@ -439,12 +439,16 @@ def get(self, request, muid): ).get_failure_response() class UsertermAPI(APIView): - def post(self, request,muid): - user = User.objects.get(muid=muid) + def post(self, request, muid): + try: + user = User.objects.get(muid=muid) + except User.DoesNotExist: + return CustomResponse(response="The user does not exist").get_failure_response() + try: settings = UserSettings.objects.get(user=user) except UserSettings.DoesNotExist: - return CustomResponse(response="The user setting doesn't exists").get_failure_response() + return CustomResponse(response="The user settings don't exist").get_failure_response() serializer = UserTermSerializer(settings, data={"is_userterms_approved": True}, partial=True) if serializer.is_valid(): @@ -453,18 +457,24 @@ def post(self, request,muid): response_data = {"message": "User terms have been successfully approved."} return CustomResponse(response=response_data).get_success_response() else: - return CustomResponse(response="The given muid seems to be invalid").get_failure_response() - return CustomResponse(response="Invalid data provided.").get_failure_response() - - def get(self,request,muid): - user = User.objects.get(muid=muid) - try: - settings = UserSettings.objects.get(user=user) - except UserSettings.DoesNotExist: - return CustomResponse(response="The user settings doesn't exists").get_failure_response() - if settings.is_userterms_approved: - response_data = {"message": "User terms are approved."} - return CustomResponse(response=response_data).get_success_response() - else: - response_data = {"message": "User terms are not approved."} - return CustomResponse(response=response_data).get_failure_response() + response_data = {"message": "The user terms have not been successfully approved."} + return CustomResponse(response=response_data).get_failure_response() + return CustomResponse(response="Invalid data provided").get_failure_response() + + def get(self, request, muid): + try: + user = User.objects.get(muid=muid) + except User.DoesNotExist: + return CustomResponse(response="The user does not exist").get_failure_response() + + try: + settings = UserSettings.objects.get(user=user) + except UserSettings.DoesNotExist: + return CustomResponse(response="The user settings don't exist").get_failure_response() + + if settings.is_userterms_approved: + response_data = {"message": "User terms are approved."} + return CustomResponse(response=response_data).get_success_response() + else: + response_data = {"message": "User terms are not approved."} + return CustomResponse(response=response_data).get_failure_response()