diff --git a/graphql/resolvers/users.js b/graphql/resolvers/users.js index 4bb2a41..df087ea 100644 --- a/graphql/resolvers/users.js +++ b/graphql/resolvers/users.js @@ -428,6 +428,8 @@ module.exports = { }; }, + + async deleteUser(_, {}, contextValue) { if (!contextValue.user) { throw new GraphQLError( @@ -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, diff --git a/graphql/typeDefs.js b/graphql/typeDefs.js index bc8e515..a8aa4cf 100644 --- a/graphql/typeDefs.js +++ b/graphql/typeDefs.js @@ -34,6 +34,7 @@ module.exports = gql` lastLogin: String! emailAuthenticated: String permission: String! + hasProfileImage: Boolean } ## User/Gear Aux Model @@ -104,6 +105,11 @@ module.exports = gql` remember: String! } + input UpdateProfileImageInput { + username: String! + hasProfileImage: Boolean! + } + input AddGearInput { username: String! type: String! @@ -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! diff --git a/models/User.js b/models/User.js index ac089c4..02066f1 100644 --- a/models/User.js +++ b/models/User.js @@ -120,6 +120,10 @@ const userSchema = new Schema({ type: String, default: "member", }, + hasProfileImage: { + type: Boolean, + default: false, + }, equipment: [gearSchema], eventsHosted: [String], eventsJoined: [String],