From a41f94d1f38492589ad2c206bab868aafda20733 Mon Sep 17 00:00:00 2001 From: Sachin Bisht Date: Tue, 28 May 2024 19:06:46 +0530 Subject: [PATCH] fix logic to get active fields from payload --- api/helpers/common_helper.py | 5 ++--- api/services/user_activities_service.py | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/api/helpers/common_helper.py b/api/helpers/common_helper.py index 4815773..cecf62b 100644 --- a/api/helpers/common_helper.py +++ b/api/helpers/common_helper.py @@ -1,5 +1,4 @@ from datetime import datetime, timezone -from typing import Any def get_current_utc_timestamp() -> datetime: @@ -7,12 +6,12 @@ def get_current_utc_timestamp() -> datetime: def check_activity_key( - activity_key: str, activity_value: dict[str, Any], keyword: str, status: str + activity_key: str, activity_value: str, keyword: str, status: str ): return ( True if activity_key.startswith(keyword) and activity_key.endswith(status) - and activity_value["value"] == "yes" + and activity_value == "yes" else False ) diff --git a/api/services/user_activities_service.py b/api/services/user_activities_service.py index 9693aa0..0754341 100644 --- a/api/services/user_activities_service.py +++ b/api/services/user_activities_service.py @@ -16,9 +16,8 @@ def __init__(self, user, user_flow): def handle_user_activities(self, json_data: dict[str, Any]): try: current_time = common_helper.get_current_utc_timestamp() - contact_activities = json_data.get("contact", {}).get("fields", {}) - for activity_key, activity_value in contact_activities.items(): + for activity_key, activity_value in json_data.items(): user_activity = self.create_or_update_user_activity( activity_key, activity_value, current_time ) @@ -34,7 +33,7 @@ def handle_user_activities(self, json_data: dict[str, Any]): ) def create_or_update_user_activity( - self, activity_key: str, activity_value: dict[str, Any], current_time: datetime + self, activity_key: str, activity_value: str, current_time: datetime ) -> Optional[models.UserActivities]: is_started = common_helper.check_activity_key( activity_key, activity_value, "activity_", "_started" @@ -65,6 +64,7 @@ def create_activity( activity=activity_key.strip(), is_started=True, started_on=current_time, + is_succeeded=False, ) def update_succeeded_activity(