|
1 | 1 | import graphene |
2 | 2 | import os |
3 | | -from flask_jwt_extended import ( |
4 | | - create_access_token, |
5 | | - create_refresh_token, |
6 | | - verify_jwt_in_request, |
7 | | - get_jwt_identity, |
8 | | - get_jwt, |
9 | | - jwt_required, |
10 | | -) |
| 3 | +from flask_jwt_extended import create_access_token, create_refresh_token, get_jwt_identity, get_jwt, jwt_required |
11 | 4 | from functools import wraps |
12 | 5 | from datetime import datetime, timedelta, timezone |
13 | 6 | from graphene_sqlalchemy import SQLAlchemyObjectType |
|
30 | 23 | from src.models.report import Report as ReportModel |
31 | 24 | from src.models.hourly_average_capacity import HourlyAverageCapacity as HourlyAverageCapacityModel |
32 | 25 | from src.database import db_session |
33 | | -from flask import current_app |
34 | 26 |
|
35 | 27 |
|
36 | 28 | # MARK: - Gym |
@@ -257,8 +249,14 @@ class Query(graphene.ObjectType): |
257 | 249 | get_workouts_by_id = graphene.List(Workout, id=graphene.Int(), description="Get all of a user's workouts by ID.") |
258 | 250 | activities = graphene.List(Activity) |
259 | 251 | get_all_reports = graphene.List(Report, description="Get all reports.") |
260 | | - get_workout_goals = graphene.List(graphene.String, id=graphene.Int(required=True), description="Get the workout goals of a user by ID.") |
261 | | - get_user_streak = graphene.Field(graphene.JSONString, id=graphene.Int(required=True), description="Get the current and max workout streak of a user.") |
| 252 | + get_workout_goals = graphene.List( |
| 253 | + graphene.String, id=graphene.Int(required=True), description="Get the workout goals of a user by ID." |
| 254 | + ) |
| 255 | + get_user_streak = graphene.Field( |
| 256 | + graphene.JSONString, |
| 257 | + id=graphene.Int(required=True), |
| 258 | + description="Get the current and max workout streak of a user.", |
| 259 | + ) |
262 | 260 | get_hourly_average_capacities_by_facility_id = graphene.List( |
263 | 261 | HourlyAverageCapacity, facility_id=graphene.Int(), description="Get all facility hourly average capacities." |
264 | 262 | ) |
@@ -316,15 +314,15 @@ def resolve_get_weekly_workout_days(self, info, id): |
316 | 314 | def resolve_get_all_reports(self, info): |
317 | 315 | query = ReportModel.query.all() |
318 | 316 | return query |
319 | | - |
| 317 | + |
320 | 318 | @jwt_required() |
321 | 319 | def resolve_get_workout_goals(self, info, id): |
322 | 320 | user = User.get_query(info).filter(UserModel.id == id).first() |
323 | 321 | if not user: |
324 | 322 | raise GraphQLError("User with the given ID does not exist.") |
325 | 323 |
|
326 | 324 | return [day.value for day in user.workout_goal] if user.workout_goal else [] |
327 | | - |
| 325 | + |
328 | 326 | @jwt_required() |
329 | 327 | def resolve_get_user_streak(self, info, id): |
330 | 328 | user = User.get_query(info).filter(UserModel.id == id).first() |
@@ -364,7 +362,7 @@ def resolve_get_user_streak(self, info, id): |
364 | 362 | max_streak = max(max_streak, streak) |
365 | 363 |
|
366 | 364 | return {"active_streak": active_streak, "max_streak": max_streak} |
367 | | - |
| 365 | + |
368 | 366 | def resolve_get_hourly_average_capacities_by_facility_id(self, info, facility_id): |
369 | 367 | valid_facility_ids = [14492437, 8500985, 7169406, 10055021, 2323580, 16099753, 15446768, 12572681] |
370 | 368 | if facility_id not in valid_facility_ids: |
@@ -409,7 +407,6 @@ def mutate(self, info): |
409 | 407 | return RefreshAccessToken(new_access_token=new_access_token) |
410 | 408 |
|
411 | 409 |
|
412 | | -# WHAT happens if a user tries to access this route if they are not logged in? |
413 | 410 | class LogoutUser(graphene.Mutation): |
414 | 411 | success = graphene.Boolean() |
415 | 412 |
|
|
0 commit comments