Skip to content

Commit

Permalink
Merge pull request #2231 from aswanthabam/dev
Browse files Browse the repository at this point in the history
fix: issue with user level api
  • Loading branch information
shaheenhyderk authored Sep 26, 2024
2 parents 26821c4 + 2cc6207 commit f407f41
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions api/dashboard/profile/profile_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ class Meta:
model = Level
fields = ("name", "tasks", "karma")

def _get_completed_tasks(self, user_id):
if getattr(self, "completed_tasks", None):
return self.completed_tasks
self.completed_tasks = list(
KarmaActivityLog.objects.filter(user=user_id, appraiser_approved=True)
.select_related("task__id")
.values_list("task__id", flat=True)
)
return self.completed_tasks

def get_tasks(self, obj):
user_id = self.context.get("user_id")
user_igs = UserIgLink.objects.filter(user__id=user_id).values_list(
Expand All @@ -215,9 +225,7 @@ def get_tasks(self, obj):
if obj.level_order > 4:
tasks = tasks.filter(ig__name__in=user_igs)

completed_tasks = KarmaActivityLog.objects.filter(
user=user_id, appraiser_approved=True
).values_list("task__id")
completed_tasks = self._get_completed_tasks(user_id)
return [
{
"task_name": task.title,
Expand All @@ -227,7 +235,7 @@ def get_tasks(self, obj):
"karma": task.karma,
}
for task in tasks
if (is_completed := task.id in completed_tasks) or task.active
if (is_completed := (task.id in completed_tasks)) or task.active
]


Expand Down

0 comments on commit f407f41

Please sign in to comment.