Skip to content

Commit

Permalink
fix: interval validation and datetime in utc timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
kaditya97 committed Dec 12, 2023
1 parent 348de44 commit 0a3e152
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions backend/api/projects/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ def get(self):
default: Token sessionTokenHere==
- name: interval
in: path
description: Time interval to get active project
description: Time interval in hours to get active project
required: false
type: integer
default: 24
Expand All @@ -1197,6 +1197,9 @@ def get(self):
500:
description: Internal Server Error
"""
interval = int(request.args.get("interval", 24))
interval = request.args.get("interval", "24")
if not interval.isdigit():
return {"Error": "Interval must be a number greater than 0"}, 400
interval = int(interval)
projects_dto = ProjectService.get_active_projects(interval)
return projects_dto, 200
4 changes: 2 additions & 2 deletions backend/services/project_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from cachetools import TTLCache, cached
from flask import current_app
import geojson
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone

from backend.exceptions import NotFound
from backend.models.dtos.mapping_dto import TaskDTOs
Expand Down Expand Up @@ -620,7 +620,7 @@ def send_email_on_project_progress(project_id):

@staticmethod
def get_active_projects(interval):
action_date = datetime.now() - timedelta(hours=interval)
action_date = datetime.now(timezone.utc) - timedelta(hours=interval)
result = (
TaskHistory.query.with_entities(TaskHistory.project_id)
.distinct()
Expand Down

0 comments on commit 0a3e152

Please sign in to comment.