From 279ba38b441e2b6d4604359e65c2e8d3fe89e89b Mon Sep 17 00:00:00 2001 From: Tran Tran Date: Wed, 9 Sep 2026 01:32:42 -0400 Subject: [PATCH 1/2] fix report google sheets sync - initialize google sheets client in report api --- src/schema.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/schema.py b/src/schema.py index 95657cf..9099778 100644 --- a/src/schema.py +++ b/src/schema.py @@ -2,6 +2,7 @@ import graphene import base64 +import gspread import os from flask_jwt_extended import create_access_token, create_refresh_token, get_jwt_identity, get_jwt, jwt_required from functools import wraps @@ -28,7 +29,12 @@ from src.models.report import Report as ReportModel from src.models.hourly_average_capacity import HourlyAverageCapacity as HourlyAverageCapacityModel from src.models.user_workout_goal_history import UserWorkoutGoalHistory as UserWorkoutGoalHistoryModel -from src.utils.constants import get_digital_ocean_s3_endpoint_url +from src.utils.constants import ( + SERVICE_ACCOUNT_PATH, + SHEET_KEY, + SHEET_REPORTS, + get_digital_ocean_s3_endpoint_url, +) from src.database import db_session import requests from firebase_admin import messaging @@ -38,6 +44,11 @@ import boto3 from botocore.config import Config +# Configure the spreadsheet used to mirror user-submitted reports. SHEET_KEY +# selects the development or production spreadsheet based on FLASK_ENV. +gc = gspread.service_account(filename=SERVICE_ACCOUNT_PATH) +sh = gc.open_by_key(SHEET_KEY) + local_tz = ZoneInfo("America/New_York") def resolve_enum_value(entry): From 3581de08887c7d51bd33f0fcdf47ea5005c3a1ae Mon Sep 17 00:00:00 2001 From: Tran Tran Date: Wed, 9 Sep 2026 01:52:16 -0400 Subject: [PATCH 2/2] Use server time for report timestamps Record report creation time at API receipt while retaining the existing createdAt input for frontend compatibility --- src/schema.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/schema.py b/src/schema.py index 9099778..1a314f4 100644 --- a/src/schema.py +++ b/src/schema.py @@ -1198,13 +1198,15 @@ def mutate(self, info, description, issue, created_at, gym_id): "OTHER", ]: raise GraphQLError("Issue is not a valid enumeration.") - created_at_utc = ensure_utc(created_at) - report = ReportModel(description=description, issue=issue, created_at=created_at_utc, gym_id=gym_id) + # Keep accepting the client timestamp for backwards compatibility, but + # use the time this request reached the server as the source of truth. + submitted_at = datetime.now(timezone.utc) + report = ReportModel(description=description, issue=issue, created_at=submitted_at, gym_id=gym_id) db_session.add(report) db_session.commit() try: - sh.worksheet(SHEET_REPORTS).append_row([report.id, issue, gym.name, description, created_at.isoformat()]) + sh.worksheet(SHEET_REPORTS).append_row([report.id, issue, gym.name, description, submitted_at.isoformat()]) except Exception as e: print(f"Error logging report to sheet: {e}")