mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 16:44:54 +00:00
sonar issues
This commit is contained in:
@ -76,12 +76,15 @@ ERROR_CODE = {
|
||||
"2043": "Article Survey with given id doesn't exist.",
|
||||
"2044": "Task does not exist",
|
||||
"2045": "Invalid guardian",
|
||||
# past due date
|
||||
"2046": "Due date must be future date",
|
||||
# invalid junior id msg
|
||||
"2047": "Invalid Junior ID ",
|
||||
"2048": "Choose right file for image",
|
||||
# task request
|
||||
"2049": "This task is already requested ",
|
||||
"2059": "Already exist junior",
|
||||
# task status
|
||||
"2060": "Task does not exist or not in pending state"
|
||||
}
|
||||
"""Success message code"""
|
||||
|
||||
@ -1,6 +1,11 @@
|
||||
"""Views of Guardian"""
|
||||
|
||||
# django imports
|
||||
# Import IsAuthenticated
|
||||
# Import viewsets and status
|
||||
# Import PageNumberPagination
|
||||
# Import User
|
||||
# Import timezone
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework import viewsets, status
|
||||
from rest_framework.pagination import PageNumberPagination
|
||||
@ -18,7 +23,8 @@ from django.utils import timezone
|
||||
# from utils file
|
||||
# Import account's serializer
|
||||
# Import account's task
|
||||
|
||||
# Import notification constant
|
||||
# Import send_notification function
|
||||
from .serializers import (UserSerializer, CreateGuardianSerializer, TaskSerializer, TaskDetailsSerializer,
|
||||
TopJuniorSerializer, ApproveJuniorSerializer, ApproveTaskSerializer)
|
||||
from .models import Guardian, JuniorTask
|
||||
@ -58,12 +64,14 @@ class SignupViewset(viewsets.ModelViewSet):
|
||||
user = serializer.save()
|
||||
"""Generate otp"""
|
||||
otp = generate_otp()
|
||||
# expire otp after 1 day
|
||||
expiry = timezone.now() + timezone.timedelta(days=1)
|
||||
# create user email otp object
|
||||
UserEmailOtp.objects.create(email=request.data['email'], otp=otp,
|
||||
user_type=str(request.data['user_type']), expired_at=expiry)
|
||||
"""Send email to the register user"""
|
||||
send_otp_email(request.data['email'], otp)
|
||||
# send push notification for registration
|
||||
send_notification(REGISTRATION, None, user.id, {})
|
||||
return custom_response(SUCCESS_CODE['3001'],
|
||||
response_status=status.HTTP_200_OK)
|
||||
|
||||
@ -112,7 +112,8 @@ class JuniorPoints(models.Model):
|
||||
|
||||
class JuniorGuardianRelationship(models.Model):
|
||||
"""Junior Guardian relationship model"""
|
||||
guardian = models.ForeignKey(Guardian, on_delete=models.CASCADE, related_name='guardian_relation', verbose_name='Guardian')
|
||||
guardian = models.ForeignKey(Guardian, on_delete=models.CASCADE, related_name='guardian_relation',
|
||||
verbose_name='Guardian')
|
||||
# associated junior with the task
|
||||
junior = models.ForeignKey(Junior, on_delete=models.CASCADE, related_name='junior_relation', verbose_name='Junior')
|
||||
# relation between guardian and junior"""
|
||||
|
||||
@ -20,6 +20,10 @@ import requests
|
||||
# Import account's serializer
|
||||
# Import account's task
|
||||
# import junior serializer
|
||||
# Import update_positions_based_on_points
|
||||
# Import upload_image_to_alibaba
|
||||
# Import custom_response, custom_error_response
|
||||
# Import constants
|
||||
from junior.models import Junior, JuniorPoints
|
||||
from .serializers import (CreateJuniorSerializer, JuniorDetailListSerializer, AddJuniorSerializer,\
|
||||
RemoveJuniorSerializer, CompleteTaskSerializer, JuniorPointsSerializer,
|
||||
@ -43,7 +47,10 @@ from .utils import update_positions_based_on_points
|
||||
# approve junior API
|
||||
# create referral code
|
||||
# validation API
|
||||
|
||||
# invite guardian API
|
||||
# by junior
|
||||
# Start task
|
||||
# by junior API
|
||||
# Create your views here.
|
||||
class UpdateJuniorProfile(viewsets.ViewSet):
|
||||
"""Update junior profile"""
|
||||
@ -58,6 +65,7 @@ class UpdateJuniorProfile(viewsets.ViewSet):
|
||||
image = request.data.get('image')
|
||||
image_url = ''
|
||||
if image:
|
||||
# check image size
|
||||
if image.size == NUMBER['zero']:
|
||||
return custom_error_response(ERROR_CODE['2035'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
# convert into file
|
||||
@ -91,6 +99,7 @@ class ValidateGuardianCode(viewsets.ViewSet):
|
||||
# fetch guardian object
|
||||
guardian_data = Guardian.objects.filter(guardian_code=code).exists()
|
||||
if guardian_data:
|
||||
# successfully check guardian code
|
||||
return custom_response(SUCCESS_CODE['3013'], response_status=status.HTTP_200_OK)
|
||||
else:
|
||||
return custom_error_response(ERROR_CODE["2022"], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
@ -129,13 +138,13 @@ class AddJuniorAPIView(viewsets.ModelViewSet):
|
||||
def create(self, request, *args, **kwargs):
|
||||
""" junior list"""
|
||||
try:
|
||||
info = {'user': request.user, 'email': request.data['email'], 'first_name': request.data['first_name'],
|
||||
'last_name': request.data['last_name'], 'relationship': str(request.data['relationship'])}
|
||||
info_data = {'user': request.user, 'relationship': str(request.data['relationship']), 'email': request.data['email'], 'first_name': request.data['first_name'],
|
||||
'last_name': request.data['last_name']}
|
||||
if User.objects.filter(username=request.data['email']):
|
||||
return custom_error_response(ERROR_CODE['2059'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# use AddJuniorSerializer serializer
|
||||
serializer = AddJuniorSerializer(data=request.data, context=info)
|
||||
serializer = AddJuniorSerializer(data=request.data, context=info_data)
|
||||
if serializer.is_valid():
|
||||
# save serializer
|
||||
serializer.save()
|
||||
@ -396,6 +405,7 @@ class StartTaskAPIView(views.APIView):
|
||||
return custom_response(SUCCESS_CODE['3035'], serializer.data, response_status=status.HTTP_200_OK)
|
||||
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
||||
else:
|
||||
# task in another state
|
||||
return custom_error_response(ERROR_CODE['2060'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
except Exception as e:
|
||||
return custom_error_response(str(e), response_status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
Reference in New Issue
Block a user