mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-16 02:16:16 +00:00
jira-28 notification
This commit is contained in:
@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user