mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 08:34:55 +00:00
@ -27,7 +27,7 @@ NUMBER = {
|
|||||||
'ninety_nine': 99, 'hundred': 100, 'thirty_six_hundred': 3600
|
'ninety_nine': 99, 'hundred': 100, 'thirty_six_hundred': 3600
|
||||||
}
|
}
|
||||||
|
|
||||||
|
none = "none"
|
||||||
|
|
||||||
# Super Admin string constant for 'role'
|
# Super Admin string constant for 'role'
|
||||||
SUPER_ADMIN = "Super Admin"
|
SUPER_ADMIN = "Super Admin"
|
||||||
|
|||||||
@ -101,7 +101,11 @@ ERROR_CODE = {
|
|||||||
"2072": "You can not approve or reject this task because junior does not exist in the system",
|
"2072": "You can not approve or reject this task because junior does not exist in the system",
|
||||||
"2073": "You can not approve or reject this junior because junior does not exist in the system",
|
"2073": "You can not approve or reject this junior because junior does not exist in the system",
|
||||||
"2074": "You can not complete this task because you does not exist in the system",
|
"2074": "You can not complete this task because you does not exist in the system",
|
||||||
"2075": "Your account is deactivated. Please contact with admin"
|
"2075": "Your account is deactivated. Please contact with admin",
|
||||||
|
"2076": "This junior already associate with you",
|
||||||
|
"2077": "You can not add guardian",
|
||||||
|
"2078": "This junior is not associate with you",
|
||||||
|
|
||||||
}
|
}
|
||||||
"""Success message code"""
|
"""Success message code"""
|
||||||
SUCCESS_CODE = {
|
SUCCESS_CODE = {
|
||||||
|
|||||||
@ -166,6 +166,10 @@ class CreateTaskAPIView(viewsets.ModelViewSet):
|
|||||||
try:
|
try:
|
||||||
image = request.data['default_image']
|
image = request.data['default_image']
|
||||||
junior = request.data['junior']
|
junior = request.data['junior']
|
||||||
|
junior_id = Junior.objects.filter(id=junior).last()
|
||||||
|
guardian_data = Guardian.objects.filter(user=request.user).last()
|
||||||
|
if guardian_data.guardian_code in junior_id.guardian_code:
|
||||||
|
return custom_error_response(ERROR_CODE['2078'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
allowed_extensions = ['.jpg', '.jpeg', '.png']
|
allowed_extensions = ['.jpg', '.jpeg', '.png']
|
||||||
if not any(extension in str(image) for extension in allowed_extensions):
|
if not any(extension in str(image) for extension in allowed_extensions):
|
||||||
return custom_error_response(ERROR_CODE['2048'], response_status=status.HTTP_400_BAD_REQUEST)
|
return custom_error_response(ERROR_CODE['2048'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
@ -187,7 +191,7 @@ class CreateTaskAPIView(viewsets.ModelViewSet):
|
|||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
# save serializer
|
# save serializer
|
||||||
task = serializer.save()
|
task = serializer.save()
|
||||||
junior_id = Junior.objects.filter(id=junior).last()
|
|
||||||
send_notification_to_junior.delay(TASK_ASSIGNED, request.auth.payload['user_id'],
|
send_notification_to_junior.delay(TASK_ASSIGNED, request.auth.payload['user_id'],
|
||||||
junior_id.auth.id, {'task_id': task.id})
|
junior_id.auth.id, {'task_id': task.id})
|
||||||
return custom_response(SUCCESS_CODE['3018'], serializer.data, response_status=status.HTTP_200_OK)
|
return custom_response(SUCCESS_CODE['3018'], serializer.data, response_status=status.HTTP_200_OK)
|
||||||
@ -242,7 +246,7 @@ class TopJuniorListAPIView(viewsets.ModelViewSet):
|
|||||||
# Update the position field for each JuniorPoints object
|
# Update the position field for each JuniorPoints object
|
||||||
for index, junior in enumerate(junior_total_points):
|
for index, junior in enumerate(junior_total_points):
|
||||||
junior.position = index + 1
|
junior.position = index + 1
|
||||||
send_notification_to_junior.delay(LEADERBOARD_RANKING, None, junior.junior.auth.id, {})
|
# send_notification_to_junior.delay(LEADERBOARD_RANKING, None, junior.junior.auth.id, {})
|
||||||
junior.save()
|
junior.save()
|
||||||
serializer = self.get_serializer(junior_total_points[:NUMBER['fifteen']], many=True)
|
serializer = self.get_serializer(junior_total_points[:NUMBER['fifteen']], many=True)
|
||||||
return custom_response(None, serializer.data, response_status=status.HTTP_200_OK)
|
return custom_response(None, serializer.data, response_status=status.HTTP_200_OK)
|
||||||
|
|||||||
@ -40,7 +40,7 @@ from .serializers import (CreateJuniorSerializer, JuniorDetailListSerializer, Ad
|
|||||||
from guardian.models import Guardian, JuniorTask
|
from guardian.models import Guardian, JuniorTask
|
||||||
from guardian.serializers import TaskDetailsSerializer, TaskDetailsjuniorSerializer
|
from guardian.serializers import TaskDetailsSerializer, TaskDetailsjuniorSerializer
|
||||||
from base.messages import ERROR_CODE, SUCCESS_CODE
|
from base.messages import ERROR_CODE, SUCCESS_CODE
|
||||||
from base.constants import NUMBER, ARTICLE_STATUS
|
from base.constants import NUMBER, ARTICLE_STATUS, none
|
||||||
from account.utils import custom_response, custom_error_response
|
from account.utils import custom_response, custom_error_response
|
||||||
from guardian.utils import upload_image_to_alibaba
|
from guardian.utils import upload_image_to_alibaba
|
||||||
from .utils import update_positions_based_on_points
|
from .utils import update_positions_based_on_points
|
||||||
@ -171,7 +171,11 @@ class AddJuniorAPIView(viewsets.ModelViewSet):
|
|||||||
image_url = upload_image_to_alibaba(profile_image, filename)
|
image_url = upload_image_to_alibaba(profile_image, filename)
|
||||||
info_data.update({"image": image_url})
|
info_data.update({"image": image_url})
|
||||||
if user := User.objects.filter(username=request.data['email']).first():
|
if user := User.objects.filter(username=request.data['email']).first():
|
||||||
self.associate_guardian(user)
|
data = self.associate_guardian(user)
|
||||||
|
if data == none:
|
||||||
|
return custom_error_response(ERROR_CODE['2077'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
elif not data:
|
||||||
|
return custom_error_response(ERROR_CODE['2076'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
return custom_response(SUCCESS_CODE['3021'], response_status=status.HTTP_200_OK)
|
return custom_response(SUCCESS_CODE['3021'], response_status=status.HTTP_200_OK)
|
||||||
# use AddJuniorSerializer serializer
|
# use AddJuniorSerializer serializer
|
||||||
serializer = AddJuniorSerializer(data=request.data, context=info_data)
|
serializer = AddJuniorSerializer(data=request.data, context=info_data)
|
||||||
@ -184,9 +188,16 @@ class AddJuniorAPIView(viewsets.ModelViewSet):
|
|||||||
return custom_error_response(str(e), response_status=status.HTTP_400_BAD_REQUEST)
|
return custom_error_response(str(e), response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
def associate_guardian(self, user):
|
def associate_guardian(self, user):
|
||||||
junior = Junior.objects.filter(auth=user).first()
|
junior = Junior.objects.filter(auth__email=self.request.data['email']).first()
|
||||||
guardian = Guardian.objects.filter(user=self.request.user).first()
|
guardian = Guardian.objects.filter(user=self.request.user).first()
|
||||||
junior.guardian_code = [guardian.guardian_code]
|
if not junior:
|
||||||
|
return none
|
||||||
|
if guardian.guardian_code in junior.guardian_code:
|
||||||
|
return False
|
||||||
|
if type(junior.guardian_code) is list:
|
||||||
|
junior.guardian_code.append(guardian.guardian_code)
|
||||||
|
else:
|
||||||
|
junior.guardian_code = [guardian.guardian_code]
|
||||||
junior.guardian_code_status = str(NUMBER['two'])
|
junior.guardian_code_status = str(NUMBER['two'])
|
||||||
junior.save()
|
junior.save()
|
||||||
JuniorGuardianRelationship.objects.get_or_create(guardian=guardian, junior=junior,
|
JuniorGuardianRelationship.objects.get_or_create(guardian=guardian, junior=junior,
|
||||||
|
|||||||
Reference in New Issue
Block a user