diff --git a/src/resolvers/Mutation/removeMember.ts b/src/resolvers/Mutation/removeMember.ts index 997ef17cc2..2353f60b76 100644 --- a/src/resolvers/Mutation/removeMember.ts +++ b/src/resolvers/Mutation/removeMember.ts @@ -5,7 +5,6 @@ import { MEMBER_NOT_FOUND_ERROR, ORGANIZATION_NOT_FOUND_ERROR, USER_NOT_FOUND_ERROR, - USER_REMOVING_SELF, } from "../../constants"; import { errors, requestContext } from "../../libraries"; import type { InterfaceOrganization } from "../../models"; @@ -13,7 +12,6 @@ import { Organization, User } from "../../models"; import { cacheOrganizations } from "../../services/OrganizationCache/cacheOrganizations"; import { findOrganizationsInCache } from "../../services/OrganizationCache/findOrganizationsInCache"; import type { MutationResolvers } from "../../types/generatedGraphQLTypes"; -import { adminCheck } from "../../utilities"; /** * This function enables to remove a member. * @param _parent - parent of current request @@ -29,7 +27,6 @@ import { adminCheck } from "../../utilities"; export const removeMember: MutationResolvers["removeMember"] = async ( _parent, args, - context, ) => { let organization: InterfaceOrganization; @@ -55,13 +52,6 @@ export const removeMember: MutationResolvers["removeMember"] = async ( ); } - const currentUser = await User.findOne({ - _id: context.userId, - }); - - // Checks whether current user making the request is an admin of organization. - await adminCheck(context.userId, organization); - const user = await User.findOne({ _id: args.data.userId, }).lean(); @@ -87,15 +77,6 @@ export const removeMember: MutationResolvers["removeMember"] = async ( ); } - // Check if the current user is removing self - if (user._id.equals(currentUser?._id)) { - throw new errors.ConflictError( - requestContext.translate(USER_REMOVING_SELF.MESSAGE), - USER_REMOVING_SELF.CODE, - USER_REMOVING_SELF.PARAM, - ); - } - const userIsOrganizationAdmin = organization?.admins.some((admin) => new mongoose.Types.ObjectId(admin.toString()).equals(user._id), ); diff --git a/tests/resolvers/Mutation/removeMember.spec.ts b/tests/resolvers/Mutation/removeMember.spec.ts index 7fa488ab11..8fbdf4f397 100644 --- a/tests/resolvers/Mutation/removeMember.spec.ts +++ b/tests/resolvers/Mutation/removeMember.spec.ts @@ -19,7 +19,6 @@ import { ADMIN_REMOVING_CREATOR, MEMBER_NOT_FOUND_ERROR, ORGANIZATION_NOT_FOUND_ERROR, - USER_NOT_AUTHORIZED_ADMIN, USER_NOT_FOUND_ERROR, USER_REMOVING_SELF, } from "../../../src/constants"; @@ -142,37 +141,8 @@ describe("resolvers -> Mutation -> removeMember", () => { await removeMemberResolverOrgNotFoundError?.({}, args, context); } catch (error: unknown) { expect(spy).toHaveBeenCalledWith(ORGANIZATION_NOT_FOUND_ERROR.MESSAGE); - } - }); - - it(`throws UnauthorizedError if current user with _id === context.userId is - not an admin of the organization with _id === args.data.organizationId`, async () => { - const { requestContext } = await import("../../../src/libraries"); - const spy = vi - .spyOn(requestContext, "translate") - .mockImplementation((message) => `Translated ${message}`); - - try { - const args: MutationRemoveMemberArgs = { - data: { - organizationId: testOrganization?.id, - userId: new Types.ObjectId().toString(), - }, - }; - - const context = { - userId: testUsers[2]?.id, - }; - - const { removeMember: removeMemberResolverAdminError } = await import( - "../../../src/resolvers/Mutation/removeMember" - ); - - await removeMemberResolverAdminError?.({}, args, context); - } catch (error: unknown) { - expect(spy).toHaveBeenCalledWith(USER_NOT_AUTHORIZED_ADMIN.MESSAGE); expect((error as Error).message).toEqual( - `Translated ${USER_NOT_AUTHORIZED_ADMIN.MESSAGE}`, + `Translated ${ORGANIZATION_NOT_FOUND_ERROR.MESSAGE}`, ); } });