Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 28 May 2024 #53

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions api/helpers/common_helper.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
from datetime import datetime, timezone
from typing import Any


def get_current_utc_timestamp() -> datetime:
return datetime.now(timezone.utc)


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
)
6 changes: 3 additions & 3 deletions api/services/user_activities_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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"
Expand Down Expand Up @@ -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(
Expand Down
Loading