Skip to content

Commit

Permalink
Merge pull request #67 from DostEducation/develop
Browse files Browse the repository at this point in the history
Release 18 July 2024
  • Loading branch information
Sachinbisht27 authored Jul 18, 2024
2 parents 5562031 + 30b0468 commit 9aa0ede
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
8 changes: 2 additions & 6 deletions api/helpers/common_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ def get_current_utc_timestamp() -> datetime:
return datetime.now(timezone.utc)


def check_activity_key(
activity_key: str, activity_value: str, keyword: str, status: str
):
def validate_activity_status(activity_key: str, keyword: str, status: str):
return (
True
if activity_key.startswith(keyword)
and activity_key.endswith(status)
and activity_value == "yes"
if activity_key.startswith(keyword) and activity_key.endswith(status)
else False
)
7 changes: 6 additions & 1 deletion api/services/flow_run_log_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ def create_user_flow_log(self, json_data: dict[str, Any]) -> models.UserFlows:
)
)

if flow_status == self.class_model.FlowRunStatus.SENT:
if flow_status == self.class_model.FlowRunStatus.SENT or (
flow_status == self.class_model.FlowRunStatus.COMPLETED
and latest_flow_log is None
):
user_flow_log = self.create_log(flow_uuid, flow_name, flow_type)
elif flow_status == self.class_model.FlowRunStatus.COMPLETED:
user_flow_log = self.update_log(latest_flow_log)
else:
user_flow_log = latest_flow_log

except Exception as e:
logger.error(
Expand Down
18 changes: 9 additions & 9 deletions api/services/user_activities_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def handle_user_activities(self, json_data: dict[str, Any]):
try:
current_time = common_helper.get_current_utc_timestamp()

for activity_key, activity_value in json_data.items():
for activity_key, _ in json_data.items():
user_activity = self.create_or_update_user_activity(
activity_key, activity_value, current_time
activity_key, current_time
)
if user_activity:
db.session.add(user_activity)
Expand All @@ -33,16 +33,16 @@ def handle_user_activities(self, json_data: dict[str, Any]):
)

def create_or_update_user_activity(
self, activity_key: str, activity_value: str, current_time: datetime
self, activity_key: str, current_time: datetime
) -> Optional[models.UserActivities]:
is_started = common_helper.check_activity_key(
activity_key, activity_value, "activity_", "_started"
is_started = common_helper.validate_activity_status(
activity_key, "activity_", "_started"
)
is_succeeded = common_helper.check_activity_key(
activity_key, activity_value, "activity_", "_success"
is_succeeded = common_helper.validate_activity_status(
activity_key, "activity_", "_success"
)
is_completed = common_helper.check_activity_key(
activity_key, activity_value, "activity_", "_completed"
is_completed = common_helper.validate_activity_status(
activity_key, "activity_", "_completed"
)

if is_started:
Expand Down

0 comments on commit 9aa0ede

Please sign in to comment.