|
3 | 3 | import os |
4 | 4 | from flask_jwt_extended import create_access_token, create_refresh_token, get_jwt_identity, get_jwt, jwt_required |
5 | 5 | from functools import wraps |
6 | | -from datetime import datetime, timedelta, timezone |
| 6 | +from datetime import datetime, timedelta, time, timezone |
7 | 7 | from graphene_sqlalchemy import SQLAlchemyObjectType |
8 | 8 | from graphql import GraphQLError |
9 | 9 | from src.models.capacity import Capacity as CapacityModel |
|
30 | 30 | import requests |
31 | 31 | from firebase_admin import messaging |
32 | 32 | import logging |
| 33 | +from zoneinfo import ZoneInfo |
33 | 34 | from sqlalchemy import func, cast, Date |
34 | 35 |
|
| 36 | +local_tz = ZoneInfo("America/New_York") |
35 | 37 |
|
36 | 38 | def resolve_enum_value(entry): |
37 | 39 | """Return the raw value for Enum objects while leaving plain strings untouched.""" |
@@ -67,7 +69,7 @@ def to_local_time(dt): |
67 | 69 | return None |
68 | 70 |
|
69 | 71 | # Convert to local timezone (server-local) |
70 | | - return dt_utc.astimezone() |
| 72 | + return dt_utc.astimezone(local_tz) |
71 | 73 |
|
72 | 74 |
|
73 | 75 | def goal_at(goal_history, window_start_date): |
@@ -264,9 +266,14 @@ class Meta: |
264 | 266 | total_gym_days = graphene.Int( |
265 | 267 | required=True, description="Get the total number of gym days (unique workout days) for user." |
266 | 268 | ) |
267 | | - streak_start = graphene.Date( |
268 | | - description="The start date of the most recent active streak, up until the current date." |
| 269 | + streak_start = graphene.DateTime( |
| 270 | + description="The start datetime of the most recent active streak (midnight of the day in local timezone), up until the current date." |
269 | 271 | ) |
| 272 | + workout_history = graphene.List(lambda: Workout) |
| 273 | + |
| 274 | + def resolve_workout_history(self, info): |
| 275 | + query = Workout.get_query(info).filter(WorkoutModel.user_id == self.id).order_by(WorkoutModel.workout_time.desc()) |
| 276 | + return query.all() |
270 | 277 |
|
271 | 278 | def resolve_total_gym_days(self, info): |
272 | 279 | return ( |
@@ -432,8 +439,8 @@ def goal_for_window_start(ws_date): |
432 | 439 | return None |
433 | 440 |
|
434 | 441 | last_streak_start_date = workout_dates[idx_last_streak_start] |
435 | | - |
436 | | - return last_streak_start_date |
| 442 | + local_midnight = datetime.combine(last_streak_start_date, time.min, tzinfo=local_tz) |
| 443 | + return local_midnight |
437 | 444 |
|
438 | 445 | def resolve_max_streak(self, info): |
439 | 446 | user = User.get_query(info).filter(UserModel.id == self.id).first() |
|
0 commit comments