Skip to content
Open
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
21 changes: 17 additions & 4 deletions src/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -1187,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}")

Expand Down
Loading