diff --git a/eslint.config.mjs b/eslint.config.mjs index 52481f3548..16ddae464e 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -14,8 +14,8 @@ import * as graphqlEslint from "@graphql-eslint/eslint-plugin"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const compat = new FlatCompat({ - baseDirectory: __dirname, - recommendedConfig: js.configs.recommended, + baseDirectory: __dirname, + recommendedConfig: js.configs.recommended }); export default [ @@ -44,7 +44,9 @@ export default [ languageOptions: { parser: tsParser, - globals: globals.node, + globals: { + ...globals.node, + }, }, rules: { "no-restricted-imports": [ @@ -142,7 +144,7 @@ export default [ }, languageOptions: { - parser: parser, + parser: graphqlEslint.parser, }, }, { diff --git a/package-lock.json b/package-lock.json index ef8e8e5559..8e4572e55a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3456,6 +3456,7 @@ "resolved": "https://registry.npmjs.org/@graphql-eslint/eslint-plugin/-/eslint-plugin-3.20.1.tgz", "integrity": "sha512-RbwVlz1gcYG62sECR1u0XqMh8w5e5XMCCZoMvPQ3nJzEBCTfXLGX727GBoRmSvY1x4gJmqNZ1lsOX7lZY14RIw==", "dev": true, + "license": "MIT", "dependencies": { "@babel/code-frame": "^7.18.6", "@graphql-tools/code-file-loader": "^7.3.6", diff --git a/src/resolvers/Mutation/sendMembershipRequest.ts b/src/resolvers/Mutation/sendMembershipRequest.ts index cd4e94767b..12dadc1587 100644 --- a/src/resolvers/Mutation/sendMembershipRequest.ts +++ b/src/resolvers/Mutation/sendMembershipRequest.ts @@ -78,8 +78,9 @@ export const sendMembershipRequest: MutationResolvers["sendMembershipRequest"] = // Checks if the user is blocked const user = await User.findById(context.userId).lean(); + if ( - user !== null && + user != null && organization.blockedUsers.some((blockedUser) => new mongoose.Types.ObjectId(blockedUser.toString()).equals(user._id), ) @@ -96,8 +97,24 @@ export const sendMembershipRequest: MutationResolvers["sendMembershipRequest"] = user: context.userId, organization: organization._id, }); - if (membershipRequestExists) { + // Check if the request is already in the user's document + if ( + user != null && + !user.membershipRequests.includes(membershipRequestExists._id) + ) { + // If it's not in the user's document, add it + await User.findByIdAndUpdate( + context.userId, + { + $push: { + membershipRequests: membershipRequestExists._id, + }, + }, + { new: true, runValidators: true }, + ); + } + throw new errors.ConflictError( requestContext.translate(MEMBERSHIP_REQUEST_ALREADY_EXISTS.MESSAGE), MEMBERSHIP_REQUEST_ALREADY_EXISTS.CODE, @@ -105,12 +122,13 @@ export const sendMembershipRequest: MutationResolvers["sendMembershipRequest"] = ); } + // Creating Membership Request const createdMembershipRequest = await MembershipRequest.create({ user: context.userId, organization: organization._id, }); - // add membership request to organization + // Updating Membership Request in organization const updatedOrganization = await Organization.findOneAndUpdate( { _id: organization._id, @@ -129,16 +147,15 @@ export const sendMembershipRequest: MutationResolvers["sendMembershipRequest"] = await cacheOrganizations([updatedOrganization]); } - // add membership request to user - await User.updateOne( - { - _id: context.userId, - }, + // Updating User + await User.findByIdAndUpdate( + context.userId, { $push: { membershipRequests: createdMembershipRequest._id, }, }, + { new: true, runValidators: true }, ); return createdMembershipRequest.toObject();