Skip to content
Draft
Show file tree
Hide file tree
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
28 changes: 28 additions & 0 deletions graphql/resolvers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ module.exports = {
};
},



async deleteUser(_, {}, contextValue) {
if (!contextValue.user) {
throw new GraphQLError(
Expand Down Expand Up @@ -477,6 +479,32 @@ module.exports = {
return user;
},

async updateProfileImage(_, { updateProfileImageInput: { username, hasProfileImage }}) {
try {
const user = await User.findOneAndUpdate(
{ username },
{ hasProfileImage },
{ new: true } // Ensure the updated document is returned
);

if (!user) {
throw new GraphQLError('User not found.', {
extensions: {
code: 'USER_NOT_FOUND',
},
});
}
return user;
}
catch (error) {
throw new GraphQLError(error, {
extensions: {
code: 'Internal Server Error',
},
});
}
},

/*
Front-end should cache all unique calls to this function. If calling for the first time,
include just these arguments: USERNAME, LOCATIONNAME. If calling on a cached query,
Expand Down
7 changes: 7 additions & 0 deletions graphql/typeDefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module.exports = gql`
lastLogin: String!
emailAuthenticated: String
permission: String!
hasProfileImage: Boolean
}

## User/Gear Aux Model
Expand Down Expand Up @@ -104,6 +105,11 @@ module.exports = gql`
remember: String!
}

input UpdateProfileImageInput {
username: String!
hasProfileImage: Boolean!
}

input AddGearInput {
username: String!
type: String!
Expand Down Expand Up @@ -221,6 +227,7 @@ module.exports = gql`
# Users
register(registerInput: RegisterInput!): User!
login(loginInput: LoginInput!): User!
updateProfileImage(updateProfileImageInput: UpdateProfileImageInput!): User!
addGear(addGearInput: AddGearInput!): [Gear]!
removeGear(username: String!, gearID: String!): [Gear]!
setRegion(setRegionInput: SetRegionInput!): User!
Expand Down
4 changes: 4 additions & 0 deletions models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ const userSchema = new Schema({
type: String,
default: "member",
},
hasProfileImage: {
type: Boolean,
default: false,
},
equipment: [gearSchema],
eventsHosted: [String],
eventsJoined: [String],
Expand Down