Fakultas Ilmu Komputer UI

Commit 56719bc2 authored by Kefas Satrio Bangkit Solidedantyo's avatar Kefas Satrio Bangkit Solidedantyo
Browse files

Merge branch 'adding-user-phone-number' into 'staging'

Adding user phone number

See merge request !87
parents 3954aa76 cc52de5f
Pipeline #84150 passed with stages
in 26 minutes and 12 seconds
...@@ -58,6 +58,13 @@ class CustomUserDetailsSerializer(serializers.ModelSerializer): ...@@ -58,6 +58,13 @@ class CustomUserDetailsSerializer(serializers.ModelSerializer):
result['role'] = instance.groups.first().name result['role'] = instance.groups.first().name
if instance.is_staff: if instance.is_staff:
result['role'] = 'admin' result['role'] = 'admin'
onboarding_status = UserAuthSerializer(instance).data
if onboarding_status['is_finished_onboarding'] is True\
and 'role' in onboarding_status:
phone_number = instance.diet_questionnaire.whatsapp_no
if phone_number is None:
phone_number = instance.diet_questionnaire.handphone_no
result['phone_number'] = phone_number
return result return result
class Meta: class Meta:
......
...@@ -8,7 +8,7 @@ from dietela_quiz.models import DietProfile ...@@ -8,7 +8,7 @@ from dietela_quiz.models import DietProfile
from authentication.models import CustomUser from authentication.models import CustomUser
from nutritionists.models import Nutritionist from nutritionists.models import Nutritionist
from diet_questionnaire.models import DietQuestionnaire from diet_questionnaire.models import DietQuestionnaire
from authentication.serializers import CustomUserDetailsSerializer from authentication.serializers import CustomUserDetailsSerializer,UserAuthSerializer
from django.db.models import Q from django.db.models import Q
from .models import DietRecommendation from .models import DietRecommendation
...@@ -160,15 +160,18 @@ class GetProfilesAndCSVTest(APITestCase): ...@@ -160,15 +160,18 @@ class GetProfilesAndCSVTest(APITestCase):
users = CustomUser.objects.all() users = CustomUser.objects.all()
users = users.order_by('name') users = users.order_by('name')
for user in users: for user in users:
expected_response.append({ onboarding_status = UserAuthSerializer(user).data
'user': CustomUserDetailsSerializer(user).data, if onboarding_status['is_finished_onboarding'] == True\
'diet_profile_id': user.diet_profile.id \ and onboarding_status['role']=="client":
if user.diet_profile is not None else None, expected_response.append({
'diet_questionnaire_id': user.diet_questionnaire.id \ 'user': CustomUserDetailsSerializer(user).data,
if hasattr(user, 'diet_questionnaire') else None, 'diet_profile_id': user.diet_profile.id \
'diet_recommendation_id': user.diet_recommendation.id \ if user.diet_profile is not None else None,
if hasattr(user, 'diet_recommendation') else None 'diet_questionnaire_id': user.diet_questionnaire.id \
}) if hasattr(user, 'diet_questionnaire') else None,
'diet_recommendation_id': user.diet_recommendation.id \
if hasattr(user, 'diet_recommendation') else None
})
self.assertEqual(response.data, expected_response) self.assertEqual(response.data, expected_response)
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
...@@ -179,15 +182,18 @@ class GetProfilesAndCSVTest(APITestCase): ...@@ -179,15 +182,18 @@ class GetProfilesAndCSVTest(APITestCase):
users = CustomUser.objects.filter(name="tesb") users = CustomUser.objects.filter(name="tesb")
users = users.order_by('name') users = users.order_by('name')
for user in users: for user in users:
expected_response.append({ onboarding_status = UserAuthSerializer(user).data
'user': CustomUserDetailsSerializer(user).data, if onboarding_status['is_finished_onboarding'] == True\
'diet_profile_id': user.diet_profile.id \ and onboarding_status['role']=="client":
if user.diet_profile is not None else None, expected_response.append({
'diet_questionnaire_id': user.diet_questionnaire.id \ 'user': CustomUserDetailsSerializer(user).data,
if hasattr(user, 'diet_questionnaire') else None, 'diet_profile_id': user.diet_profile.id \
'diet_recommendation_id': user.diet_recommendation.id \ if user.diet_profile is not None else None,
if hasattr(user, 'diet_recommendation') else None 'diet_questionnaire_id': user.diet_questionnaire.id \
}) if hasattr(user, 'diet_questionnaire') else None,
'diet_recommendation_id': user.diet_recommendation.id \
if hasattr(user, 'diet_recommendation') else None
})
self.assertEqual(response.data, expected_response) self.assertEqual(response.data, expected_response)
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
...@@ -208,15 +214,18 @@ class GetProfilesAndCSVTest(APITestCase): ...@@ -208,15 +214,18 @@ class GetProfilesAndCSVTest(APITestCase):
users = CustomUser.objects.filter(Q(nutritionist=1) & ~Q(email='test2@2test.com')) users = CustomUser.objects.filter(Q(nutritionist=1) & ~Q(email='test2@2test.com'))
expected_response = [] expected_response = []
for user in users: for user in users:
expected_response.append({ onboarding_status = UserAuthSerializer(user).data
'user': CustomUserDetailsSerializer(user).data, if onboarding_status['is_finished_onboarding'] == True\
'diet_profile_id': user.diet_profile.id \ and onboarding_status['role']=="client":
if user.diet_profile is not None else None, expected_response.append({
'diet_questionnaire_id': user.diet_questionnaire.id \ 'user': CustomUserDetailsSerializer(user).data,
if hasattr(user, 'diet_questionnaire') else None, 'diet_profile_id': user.diet_profile.id \
'diet_recommendation_id': user.diet_recommendation.id \ if user.diet_profile is not None else None,
if hasattr(user, 'diet_recommendation') else None 'diet_questionnaire_id': user.diet_questionnaire.id \
}) if hasattr(user, 'diet_questionnaire') else None,
'diet_recommendation_id': user.diet_recommendation.id \
if hasattr(user, 'diet_recommendation') else None
})
self.assertEqual(response.data, expected_response) self.assertEqual(response.data, expected_response)
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
...@@ -238,15 +247,18 @@ class GetProfilesAndCSVTest(APITestCase): ...@@ -238,15 +247,18 @@ class GetProfilesAndCSVTest(APITestCase):
users = users.order_by('name') users = users.order_by('name')
expected_response = [] expected_response = []
for user in users: for user in users:
expected_response.append({ onboarding_status = UserAuthSerializer(user).data
'user': CustomUserDetailsSerializer(user).data, if onboarding_status['is_finished_onboarding'] == True\
'diet_profile_id': user.diet_profile.id \ and onboarding_status['role']=="client":
if user.diet_profile is not None else None, expected_response.append({
'diet_questionnaire_id': user.diet_questionnaire.id \ 'user': CustomUserDetailsSerializer(user).data,
if hasattr(user, 'diet_questionnaire') else None, 'diet_profile_id': user.diet_profile.id \
'diet_recommendation_id': user.diet_recommendation.id \ if user.diet_profile is not None else None,
if hasattr(user, 'diet_recommendation') else None 'diet_questionnaire_id': user.diet_questionnaire.id \
}) if hasattr(user, 'diet_questionnaire') else None,
'diet_recommendation_id': user.diet_recommendation.id \
if hasattr(user, 'diet_recommendation') else None
})
self.assertEqual(response.data, expected_response) self.assertEqual(response.data, expected_response)
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
......
...@@ -5,7 +5,7 @@ from rest_framework.response import Response ...@@ -5,7 +5,7 @@ from rest_framework.response import Response
from django.db.models import Q from django.db.models import Q
from django.http import HttpResponse from django.http import HttpResponse
from authentication.models import CustomUser from authentication.models import CustomUser
from authentication.serializers import CustomUserDetailsSerializer from authentication.serializers import CustomUserDetailsSerializer,UserAuthSerializer
from dietela_quiz.models import DietProfile from dietela_quiz.models import DietProfile
from diet_questionnaire.models import DietQuestionnaire from diet_questionnaire.models import DietQuestionnaire
from .utilities import dp_helper,dq_helper from .utilities import dp_helper,dq_helper
...@@ -43,15 +43,18 @@ class GetProfilesViewSet(generics.ListAPIView): ...@@ -43,15 +43,18 @@ class GetProfilesViewSet(generics.ListAPIView):
response = [] response = []
for user in queryset: for user in queryset:
response.append({ onboarding_status = UserAuthSerializer(user).data
'user': CustomUserDetailsSerializer(user).data, if onboarding_status['is_finished_onboarding'] is True\
'diet_profile_id': user.diet_profile.id \ and onboarding_status['role']=="client":
if user.diet_profile is not None else None, response.append({
'diet_questionnaire_id': user.diet_questionnaire.id \ 'user': CustomUserDetailsSerializer(user).data,
if hasattr(user, 'diet_questionnaire') else None, 'diet_profile_id': user.diet_profile.id \
'diet_recommendation_id': user.diet_recommendation.id \ if user.diet_profile is not None else None,
if hasattr(user, 'diet_recommendation') else None 'diet_questionnaire_id': user.diet_questionnaire.id \
}) if hasattr(user, 'diet_questionnaire') else None,
'diet_recommendation_id': user.diet_recommendation.id \
if hasattr(user, 'diet_recommendation') else None
})
return Response(response, status=status.HTTP_200_OK) return Response(response, status=status.HTTP_200_OK)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment