Skip to content

Commit

Permalink
Merge pull request #150 from cuappdev/master
Browse files Browse the repository at this point in the history
Merge to prod
  • Loading branch information
vinnie4k authored Apr 15, 2024
2 parents 716e93c + e59e3b6 commit 302e4e6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ type Gym {

type Mutation {
createGiveaway(name: String!): CreateGiveaway
createUser(netId: String!): CreateUser
createUser(instagram: String, netId: String!): CreateUser
enterGiveaway(giveawayId: Int!, userNetId: String!): EnterGiveaway
}

Expand Down Expand Up @@ -159,6 +159,7 @@ type Query {

type User {
id: ID!
instagram: String
netId: String!
giveaways: [Giveaway]
}
2 changes: 2 additions & 0 deletions src/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ class User(Base):
Attributes:
- `id` The ID of user.
- `giveaways` (nullable) The list of giveaways a user is entered into.
- `instagram` (nullable) The username handle of this user's Instagram.
- `net_id` The user's Net ID.
"""

__tablename__ = "users"

id = Column(Integer, primary_key=True)
giveaways = relationship("Giveaway", secondary="giveaway_instance", back_populates="users")
instagram = Column(String, nullable=True)
net_id = Column(String, nullable=False)
5 changes: 3 additions & 2 deletions src/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,19 @@ def resolve_get_users_by_giveaway_id(self, info, id):

class CreateUser(graphene.Mutation):
class Arguments:
instagram = graphene.String()
net_id = graphene.String(required=True)

user = graphene.Field(User)

def mutate(root, info, net_id):
def mutate(root, info, net_id, instagram=None):
# Check to see if NetID already exists
existing_user = User.get_query(info).filter(UserModel.net_id == net_id).first()
if existing_user:
raise GraphQLError("NetID already exists.")

# NetID does not exist
new_user = UserModel(net_id=net_id)
new_user = UserModel(instagram=instagram, net_id=net_id)
db_session.add(new_user)
db_session.commit()
return CreateUser(user=new_user)
Expand Down

0 comments on commit 302e4e6

Please sign in to comment.