mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-16 18:36:18 +00:00
jira-28 notification
This commit is contained in:
@ -87,6 +87,8 @@ ERROR_CODE = {
|
||||
# task status
|
||||
"2060": "Task does not exist or not in pending state",
|
||||
"2061": "Please insert image or check the image is valid or not.",
|
||||
# email not null
|
||||
"2062": "Please enter email address"
|
||||
}
|
||||
"""Success message code"""
|
||||
SUCCESS_CODE = {
|
||||
|
Binary file not shown.
@ -25,7 +25,10 @@ from base.messages import ERROR_CODE, SUCCESS_CODE
|
||||
from base.constants import NUMBER, JUN, ZOD, GRD
|
||||
from junior.models import Junior, JuniorPoints
|
||||
from .utils import real_time, convert_timedelta_into_datetime, update_referral_points
|
||||
|
||||
# notification's constant
|
||||
from notifications.constants import TASK_POINTS, TASK_REJECTED
|
||||
# send notification function
|
||||
from notifications.utils import send_notification
|
||||
|
||||
|
||||
# In this serializer file
|
||||
@ -61,7 +64,7 @@ class UserSerializer(serializers.ModelSerializer):
|
||||
try:
|
||||
"""Create user profile"""
|
||||
user = User.objects.create_user(username=email, email=email, password=password)
|
||||
UserNotification.objects.create(user=user)
|
||||
UserNotification.objects.get_or_create(user=user)
|
||||
if user_type == str(NUMBER['one']):
|
||||
# create junior profile
|
||||
Junior.objects.create(auth=user, junior_code=generate_code(JUN, user.id),
|
||||
@ -328,27 +331,30 @@ class ApproveTaskSerializer(serializers.ModelSerializer):
|
||||
|
||||
def create(self, validated_data):
|
||||
"""update task status """
|
||||
instance = self.context['task_instance']
|
||||
junior = self.context['junior']
|
||||
junior_details = Junior.objects.filter(id=junior).last()
|
||||
junior_data, created = JuniorPoints.objects.get_or_create(junior=junior_details)
|
||||
if self.context['action'] == str(NUMBER['one']):
|
||||
# approve the task
|
||||
instance.task_status = str(NUMBER['five'])
|
||||
instance.is_approved = True
|
||||
# update total task point
|
||||
junior_data.total_points = junior_data.total_points + instance.points
|
||||
# update complete time of task
|
||||
instance.completed_on = real_time()
|
||||
else:
|
||||
# reject the task
|
||||
instance.task_status = str(NUMBER['three'])
|
||||
instance.is_approved = False
|
||||
# update total task point
|
||||
junior_data.total_points = junior_data.total_points - instance.points
|
||||
# update reject time of task
|
||||
instance.rejected_on = real_time()
|
||||
instance.save()
|
||||
junior_data.save()
|
||||
return instance
|
||||
with transaction.atomic():
|
||||
instance = self.context['task_instance']
|
||||
junior = self.context['junior']
|
||||
junior_details = Junior.objects.filter(id=junior).last()
|
||||
junior_data, created = JuniorPoints.objects.get_or_create(junior=junior_details)
|
||||
if self.context['action'] == str(NUMBER['one']):
|
||||
# approve the task
|
||||
instance.task_status = str(NUMBER['five'])
|
||||
instance.is_approved = True
|
||||
# update total task point
|
||||
junior_data.total_points = junior_data.total_points + instance.points
|
||||
# update complete time of task
|
||||
instance.completed_on = real_time()
|
||||
send_notification.delay(TASK_POINTS, None, junior_details.auth.id, {})
|
||||
else:
|
||||
# reject the task
|
||||
instance.task_status = str(NUMBER['three'])
|
||||
instance.is_approved = False
|
||||
# update total task point
|
||||
junior_data.total_points = junior_data.total_points - instance.points
|
||||
# update reject time of task
|
||||
instance.rejected_on = real_time()
|
||||
send_notification.delay(TASK_REJECTED, None, junior_details.auth.id, {})
|
||||
instance.save()
|
||||
junior_data.save()
|
||||
return junior_details
|
||||
|
||||
|
@ -18,6 +18,10 @@ from junior.models import Junior, JuniorPoints
|
||||
from .models import JuniorTask
|
||||
# Import app from celery
|
||||
from zod_bank.celery import app
|
||||
# notification's constant
|
||||
from notifications.constants import REFERRAL_POINTS
|
||||
# send notification function
|
||||
from notifications.utils import send_notification
|
||||
# Define upload image on
|
||||
# ali baba cloud
|
||||
# firstly save image
|
||||
@ -85,6 +89,8 @@ def update_referral_points(referral_code, referral_code_used):
|
||||
junior_query.total_points = junior_query.total_points + NUMBER['five']
|
||||
junior_query.referral_points = junior_query.referral_points + NUMBER['five']
|
||||
junior_query.save()
|
||||
send_notification.delay(REFERRAL_POINTS, None, junior_queryset.auth.id, {})
|
||||
|
||||
|
||||
|
||||
@app.task
|
||||
|
@ -35,7 +35,7 @@ from account.utils import custom_response, custom_error_response, OTP_EXPIRY, se
|
||||
from base.messages import ERROR_CODE, SUCCESS_CODE
|
||||
from base.constants import NUMBER
|
||||
from .utils import upload_image_to_alibaba
|
||||
from notifications.constants import REGISTRATION, TASK_CREATED
|
||||
from notifications.constants import REGISTRATION, TASK_CREATED, LEADERBOARD_RANKING
|
||||
from notifications.utils import send_notification
|
||||
|
||||
""" Define APIs """
|
||||
@ -245,6 +245,7 @@ class TopJuniorListAPIView(viewsets.ModelViewSet):
|
||||
# Update the position field for each JuniorPoints object
|
||||
for index, junior in enumerate(junior_total_points):
|
||||
junior.position = index + 1
|
||||
send_notification.delay(LEADERBOARD_RANKING, None, junior.junior.auth.id, {})
|
||||
junior.save()
|
||||
|
||||
serializer = self.get_serializer(junior_total_points, many=True)
|
||||
@ -309,11 +310,14 @@ class ApproveTaskAPIView(viewsets.ViewSet):
|
||||
"action": str(request.data['action']),
|
||||
"junior": self.request.data['junior_id']},
|
||||
data=request.data)
|
||||
if str(request.data['action']) == str(NUMBER['one']) and serializer.is_valid():
|
||||
unexpected_task_status = [str(NUMBER['five']), str(NUMBER['six'])]
|
||||
if (str(request.data['action']) == str(NUMBER['one']) and serializer.is_valid()
|
||||
and queryset[1] and queryset[1].task_status not in unexpected_task_status):
|
||||
# save serializer
|
||||
serializer.save()
|
||||
return custom_response(SUCCESS_CODE['3025'], response_status=status.HTTP_200_OK)
|
||||
elif str(request.data['action']) == str(NUMBER['two']) and serializer.is_valid():
|
||||
elif (str(request.data['action']) == str(NUMBER['two']) and serializer.is_valid()
|
||||
and queryset[1] and queryset[1].task_status not in unexpected_task_status):
|
||||
# save serializer
|
||||
serializer.save()
|
||||
return custom_response(SUCCESS_CODE['3026'], response_status=status.HTTP_200_OK)
|
||||
|
@ -18,7 +18,8 @@ from account.models import UserEmailOtp, UserNotification
|
||||
from junior.utils import junior_notification_email, junior_approval_mail
|
||||
from guardian.utils import real_time, update_referral_points, convert_timedelta_into_datetime
|
||||
from notifications.utils import send_notification
|
||||
from notifications.constants import INVITED_GUARDIAN, APPROVED_JUNIOR
|
||||
from notifications.constants import (INVITED_GUARDIAN, APPROVED_JUNIOR, SKIPPED_PROFILE_SETUP, TASK_ACTION,
|
||||
TASK_SUBMITTED)
|
||||
|
||||
|
||||
class ListCharField(serializers.ListField):
|
||||
@ -284,9 +285,13 @@ class AddJuniorSerializer(serializers.ModelSerializer):
|
||||
expiry_time = timezone.now() + timezone.timedelta(days=1)
|
||||
UserEmailOtp.objects.create(email=email, otp=otp_value,
|
||||
user_type='1', expired_at=expiry_time, is_verified=True)
|
||||
# add push notification
|
||||
UserNotification.objects.get_or_create(user=user_data)
|
||||
"""Notification email"""
|
||||
junior_notification_email(email, full_name, email, password)
|
||||
junior_approval_mail(guardian, full_name)
|
||||
# push notification
|
||||
send_notification.delay(SKIPPED_PROFILE_SETUP, None, junior_data.auth.id, {})
|
||||
return junior_data
|
||||
|
||||
|
||||
@ -317,6 +322,8 @@ class CompleteTaskSerializer(serializers.ModelSerializer):
|
||||
instance.task_status = str(NUMBER['four'])
|
||||
instance.is_approved = False
|
||||
instance.save()
|
||||
send_notification.delay(TASK_SUBMITTED, None, instance.junior.auth.id, {})
|
||||
send_notification.delay(TASK_ACTION, None, instance.guardian.user.id, {})
|
||||
return instance
|
||||
|
||||
class JuniorPointsSerializer(serializers.ModelSerializer):
|
||||
@ -393,7 +400,7 @@ class AddGuardianSerializer(serializers.ModelSerializer):
|
||||
instance.id),
|
||||
referral_code_used=junior_data.referral_code,
|
||||
is_verified=True)
|
||||
UserNotification.objects.create(user=instance)
|
||||
UserNotification.objects.get_or_create(user=instance)
|
||||
return guardian_data
|
||||
else:
|
||||
user = User.objects.create(username=email, email=email,
|
||||
@ -413,7 +420,7 @@ class AddGuardianSerializer(serializers.ModelSerializer):
|
||||
UserEmailOtp.objects.create(email=email, otp=otp_value,
|
||||
user_type=str(NUMBER['two']), expired_at=expiry_time,
|
||||
is_verified=True)
|
||||
UserNotification.objects.create(user=user)
|
||||
UserNotification.objects.get_or_create(user=user)
|
||||
JuniorGuardianRelationship.objects.create(guardian=guardian_data, junior=junior_data,
|
||||
relationship=relationship)
|
||||
|
||||
|
@ -36,6 +36,8 @@ from base.constants import NUMBER
|
||||
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
|
||||
from notifications.utils import send_notification
|
||||
from notifications.constants import REMOVE_JUNIOR
|
||||
|
||||
""" Define APIs """
|
||||
# Define validate guardian code API,
|
||||
@ -233,6 +235,7 @@ class RemoveJuniorAPIView(views.APIView):
|
||||
if serializer.is_valid():
|
||||
# save serializer
|
||||
serializer.save()
|
||||
send_notification.delay(REMOVE_JUNIOR, None, junior_queryset.auth.id, {})
|
||||
return custom_response(SUCCESS_CODE['3022'], serializer.data, response_status=status.HTTP_200_OK)
|
||||
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
||||
else:
|
||||
@ -374,6 +377,8 @@ class InviteGuardianAPIView(viewsets.ModelViewSet):
|
||||
def create(self, request, *args, **kwargs):
|
||||
""" junior list"""
|
||||
try:
|
||||
if request.data['email'] == '':
|
||||
return custom_error_response(ERROR_CODE['2062'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
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'])}
|
||||
# use AddJuniorSerializer serializer
|
||||
|
@ -1,10 +1,19 @@
|
||||
"""
|
||||
notification constants file
|
||||
"""
|
||||
|
||||
REGISTRATION = 1
|
||||
TASK_CREATED = 2
|
||||
INVITED_GUARDIAN = 3
|
||||
APPROVED_JUNIOR = 4
|
||||
REFERRAL_POINTS = 5
|
||||
TASK_POINTS = 6
|
||||
TASK_REJECTED = 7
|
||||
SKIPPED_PROFILE_SETUP = 8
|
||||
TASK_SUBMITTED = 9
|
||||
TASK_ACTION = 10
|
||||
LEADERBOARD_RANKING = 11
|
||||
REMOVE_JUNIOR = 12
|
||||
TEST_NOTIFICATION = 99
|
||||
|
||||
NOTIFICATION_DICT = {
|
||||
@ -22,7 +31,39 @@ NOTIFICATION_DICT = {
|
||||
},
|
||||
APPROVED_JUNIOR: {
|
||||
"title": "Approve junior",
|
||||
"body": "You have request for associate the junior"
|
||||
"body": "You have request from junior to associate with you"
|
||||
},
|
||||
REFERRAL_POINTS: {
|
||||
"title": "Earn Referral points",
|
||||
"body": "You earn 5 points for referral."
|
||||
},
|
||||
TASK_POINTS: {
|
||||
"title": "Earn Task points!",
|
||||
"body": "You earn 5 points for task."
|
||||
},
|
||||
TASK_REJECTED: {
|
||||
"title": "Task rejected!",
|
||||
"body": "Your task has been rejected."
|
||||
},
|
||||
SKIPPED_PROFILE_SETUP: {
|
||||
"title": "Skipped profile setup!",
|
||||
"body": "Your guardian has been setup your profile."
|
||||
},
|
||||
TASK_SUBMITTED: {
|
||||
"title": "Task submitted!",
|
||||
"body": "Your task has been submitted successfully."
|
||||
},
|
||||
TASK_ACTION: {
|
||||
"title": "Task approval!",
|
||||
"body": "You have request for task approval."
|
||||
},
|
||||
LEADERBOARD_RANKING: {
|
||||
"title": "Leader board rank!",
|
||||
"body": "Your rank is ."
|
||||
},
|
||||
REMOVE_JUNIOR: {
|
||||
"title": "Disassociate by guardian!",
|
||||
"body": "Your guardian disassociate you ."
|
||||
},
|
||||
TEST_NOTIFICATION: {
|
||||
"title": "Test Notification",
|
||||
|
Reference in New Issue
Block a user