Skip to content

Commit 8a1affd

Browse files
authored
Merge pull request #192 from cuappdev/joshua-refactor
Added delete user by id mutation
2 parents 4f39a2a + 7682b4b commit 8a1affd

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ type Mutation {
168168
setWorkoutGoals(userId: Int!, workoutGoal: [String]!): User
169169
logWorkout(userId: Int!, workoutTime: DateTime!): Workout
170170
createReport(createdAt: DateTime!, description: String!, gymId: Int!, issue: String!): CreateReport
171+
deleteUser(userId: Int!): User
171172
}
172173

173174
type OpenHours {

src/schema.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class Meta:
116116
model = CapacityModel
117117

118118

119-
#MARK - Hourly Average Capacity
119+
# MARK - Hourly Average Capacity
120120
class HourlyAverageCapacity(SQLAlchemyObjectType):
121121
class Meta:
122122
model = HourlyAverageCapacityModel
@@ -252,7 +252,7 @@ def resolve_get_all_gyms(self, info):
252252
def resolve_activities(self, info):
253253
query = Activity.get_query(info)
254254
return query.all()
255-
255+
256256
def resolve_get_user_by_net_id(self, info, net_id):
257257
user = User.get_query(info).filter(UserModel.net_id == net_id).all()
258258
if not user:
@@ -296,7 +296,7 @@ def resolve_get_weekly_workout_days(self, info, id):
296296
def resolve_get_all_reports(self, info):
297297
query = ReportModel.query.all()
298298
return query
299-
299+
300300
def resolve_get_hourly_average_capacities_by_facility_id(self, info, facility_id):
301301
valid_facility_ids = [14492437, 8500985, 7169406, 10055021, 2323580, 16099753, 15446768, 12572681]
302302
if facility_id not in valid_facility_ids:
@@ -451,6 +451,20 @@ def mutate(self, info, description, issue, created_at, gym_id):
451451
db_session.commit()
452452
return CreateReport(report=report)
453453

454+
class DeleteUserById(graphene.Mutation):
455+
class Arguments:
456+
user_id = graphene.Int(required=True)
457+
Output = User
458+
459+
def mutate(self, info, user_id):
460+
# Check if user exists
461+
user = User.get_query(info).filter(UserModel.id == user_id).first()
462+
if not user:
463+
raise GraphQLError("User with given ID does not exist.")
464+
db_session.delete(user)
465+
db_session.commit()
466+
return user
467+
454468

455469
class Mutation(graphene.ObjectType):
456470
create_giveaway = CreateGiveaway.Field(description="Creates a new giveaway.")
@@ -459,6 +473,7 @@ class Mutation(graphene.ObjectType):
459473
set_workout_goals = SetWorkoutGoals.Field(description="Set a user's workout goals.")
460474
log_workout = logWorkout.Field(description="Log a user's workout.")
461475
create_report = CreateReport.Field(description="Creates a new report.")
476+
delete_user = DeleteUserById.Field(description="Deletes a user by ID.")
462477

463478

464479
schema = graphene.Schema(query=Query, mutation=Mutation)

0 commit comments

Comments
 (0)