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