mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 08:34:55 +00:00
resolve bugs
This commit is contained in:
@ -27,7 +27,7 @@ NUMBER = {
|
||||
'ninety_nine': 99, 'hundred': 100, 'thirty_six_hundred': 3600
|
||||
}
|
||||
|
||||
|
||||
none = "none"
|
||||
|
||||
# Super Admin string constant for 'role'
|
||||
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",
|
||||
"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",
|
||||
"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_CODE = {
|
||||
|
||||
@ -164,6 +164,10 @@ class CreateTaskAPIView(viewsets.ModelViewSet):
|
||||
try:
|
||||
image = request.data['default_image']
|
||||
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']
|
||||
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)
|
||||
@ -185,7 +189,7 @@ class CreateTaskAPIView(viewsets.ModelViewSet):
|
||||
if serializer.is_valid():
|
||||
# save serializer
|
||||
task = serializer.save()
|
||||
junior_id = Junior.objects.filter(id=junior).last()
|
||||
|
||||
send_notification_to_junior.delay(TASK_ASSIGNED, request.auth.payload['user_id'],
|
||||
junior_id.auth.id, {'task_id': task.id})
|
||||
return custom_response(SUCCESS_CODE['3018'], 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.serializers import TaskDetailsSerializer, TaskDetailsjuniorSerializer
|
||||
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 guardian.utils import upload_image_to_alibaba
|
||||
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)
|
||||
info_data.update({"image": image_url})
|
||||
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)
|
||||
# use AddJuniorSerializer serializer
|
||||
serializer = AddJuniorSerializer(data=request.data, context=info_data)
|
||||
@ -184,8 +188,15 @@ class AddJuniorAPIView(viewsets.ModelViewSet):
|
||||
return custom_error_response(str(e), response_status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
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()
|
||||
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.save()
|
||||
|
||||
Reference in New Issue
Block a user