From 428fc28a33e6a717ecef40ddb860506f96a1afc7 Mon Sep 17 00:00:00 2001 From: meetul Date: Fri, 1 Nov 2024 10:27:30 +0530 Subject: [PATCH] remove getUserTagAncestors query --- schema.graphql | 1 - src/resolvers/Query/getUserTagAncestors.ts | 45 ------------- src/resolvers/Query/index.ts | 2 - src/typeDefs/queries.ts | 2 - src/types/generatedGraphQLTypes.ts | 7 -- tests/resolvers/Query/getUserTag.spec.ts | 6 +- .../Query/getUserTagAncestors.spec.ts | 64 ------------------- 7 files changed, 3 insertions(+), 124 deletions(-) delete mode 100644 src/resolvers/Query/getUserTagAncestors.ts delete mode 100644 tests/resolvers/Query/getUserTagAncestors.spec.ts diff --git a/schema.graphql b/schema.graphql index 3f84cbe292..e5ff6055ba 100644 --- a/schema.graphql +++ b/schema.graphql @@ -1504,7 +1504,6 @@ type Query { getPledgesByUserId(orderBy: PledgeOrderByInput, userId: ID!, where: PledgeWhereInput): [FundraisingCampaignPledge] getPlugins: [Plugin] getUserTag(id: ID!): UserTag - getUserTagAncestors(id: ID!): [UserTag] getVenueByOrgId(first: Int, orderBy: VenueOrderByInput, orgId: ID!, skip: Int, where: VenueWhereInput): [Venue] getlanguage(lang_code: String!): [Translation] hasSubmittedFeedback(eventId: ID!, userId: ID!): Boolean diff --git a/src/resolvers/Query/getUserTagAncestors.ts b/src/resolvers/Query/getUserTagAncestors.ts deleted file mode 100644 index cf516eb43e..0000000000 --- a/src/resolvers/Query/getUserTagAncestors.ts +++ /dev/null @@ -1,45 +0,0 @@ -import type { InterfaceOrganizationTagUser } from "../../models"; -import { OrganizationTagUser } from "../../models"; -import { errors, requestContext } from "../../libraries"; -import type { QueryResolvers } from "../../types/generatedGraphQLTypes"; -import { TAG_NOT_FOUND } from "../../constants"; - -/** - * Retrieves the ancestor tags of a given user tag. - * - * This function fetches the ancestor tags of a specific user tag from the database. If the user tag - * is not found, it throws an error indicating that the item does not exist. - * - * @param _parent - This parameter is not used in this resolver function. - * @param args - The arguments provided by the GraphQL query, including the ID of the given user tag. - * - * @returns The ancestor tags of the user tag. - */ - -export const getUserTagAncestors: QueryResolvers["getUserTagAncestors"] = - async (_parent, args) => { - let currentTag = await OrganizationTagUser.findById(args.id).lean(); - - if (!currentTag) { - throw new errors.NotFoundError( - requestContext.translate(TAG_NOT_FOUND.MESSAGE), - TAG_NOT_FOUND.CODE, - TAG_NOT_FOUND.PARAM, - ); - } - - const tagAncestors = [currentTag]; - - while (currentTag?.parentTagId) { - const currentParent = (await OrganizationTagUser.findById( - currentTag.parentTagId, - ).lean()) as InterfaceOrganizationTagUser | null; - - if (currentParent) { - tagAncestors.push(currentParent); - currentTag = currentParent; - } - } - - return tagAncestors.reverse(); - }; diff --git a/src/resolvers/Query/index.ts b/src/resolvers/Query/index.ts index e6ca8a74ed..8474b60298 100644 --- a/src/resolvers/Query/index.ts +++ b/src/resolvers/Query/index.ts @@ -32,7 +32,6 @@ import { getPledgesByUserId } from "./getPledgesByUserId"; import { getPlugins } from "./getPlugins"; import { getlanguage } from "./getlanguage"; import { getUserTag } from "./getUserTag"; -import { getUserTagAncestors } from "./getUserTagAncestors"; import { me } from "./me"; import { myLanguage } from "./myLanguage"; import { organizations } from "./organizations"; @@ -81,7 +80,6 @@ export const Query: QueryResolvers = { getlanguage, getPlugins, getUserTag, - getUserTagAncestors, isSampleOrganization, me, myLanguage, diff --git a/src/typeDefs/queries.ts b/src/typeDefs/queries.ts index b4e40c3e6c..7572b3387c 100644 --- a/src/typeDefs/queries.ts +++ b/src/typeDefs/queries.ts @@ -124,8 +124,6 @@ export const queries = gql` getUserTag(id: ID!): UserTag - getUserTagAncestors(id: ID!): [UserTag] - getAllNotesForAgendaItem(agendaItemId: ID!): [Note] advertisementsConnection( diff --git a/src/types/generatedGraphQLTypes.ts b/src/types/generatedGraphQLTypes.ts index 422c44abcf..dca6bfd813 100644 --- a/src/types/generatedGraphQLTypes.ts +++ b/src/types/generatedGraphQLTypes.ts @@ -2261,7 +2261,6 @@ export type Query = { getPledgesByUserId?: Maybe>>; getPlugins?: Maybe>>; getUserTag?: Maybe; - getUserTagAncestors?: Maybe>>; getVenueByOrgId?: Maybe>>; getlanguage?: Maybe>>; hasSubmittedFeedback?: Maybe; @@ -2478,11 +2477,6 @@ export type QueryGetUserTagArgs = { }; -export type QueryGetUserTagAncestorsArgs = { - id: Scalars['ID']['input']; -}; - - export type QueryGetVenueByOrgIdArgs = { first?: InputMaybe; orderBy?: InputMaybe; @@ -4581,7 +4575,6 @@ export type QueryResolvers>>, ParentType, ContextType, RequireFields>; getPlugins?: Resolver>>, ParentType, ContextType>; getUserTag?: Resolver, ParentType, ContextType, RequireFields>; - getUserTagAncestors?: Resolver>>, ParentType, ContextType, RequireFields>; getVenueByOrgId?: Resolver>>, ParentType, ContextType, RequireFields>; getlanguage?: Resolver>>, ParentType, ContextType, RequireFields>; hasSubmittedFeedback?: Resolver, ParentType, ContextType, RequireFields>; diff --git a/tests/resolvers/Query/getUserTag.spec.ts b/tests/resolvers/Query/getUserTag.spec.ts index f81f51d960..0e935a383a 100644 --- a/tests/resolvers/Query/getUserTag.spec.ts +++ b/tests/resolvers/Query/getUserTag.spec.ts @@ -22,7 +22,7 @@ afterAll(async () => { await disconnect(MONGOOSE_INSTANCE); }); -describe("resolvers -> Query -> getUserTagAncestors", () => { +describe("resolvers -> Query -> getUserTag", () => { it(`throws NotFoundError if no userTag exists with _id === args.id`, async () => { const { requestContext } = await import("../../../src/libraries"); @@ -49,8 +49,8 @@ describe("resolvers -> Query -> getUserTagAncestors", () => { id: testTag?._id.toString() ?? "", }; - const getUserTagAncestorsPayload = await getUserTagResolver?.({}, args, {}); + const getUserTagPayload = await getUserTagResolver?.({}, args, {}); - expect(getUserTagAncestorsPayload).toEqual(testTag); + expect(getUserTagPayload).toEqual(testTag); }); }); diff --git a/tests/resolvers/Query/getUserTagAncestors.spec.ts b/tests/resolvers/Query/getUserTagAncestors.spec.ts deleted file mode 100644 index 2a3ee00143..0000000000 --- a/tests/resolvers/Query/getUserTagAncestors.spec.ts +++ /dev/null @@ -1,64 +0,0 @@ -import "dotenv/config"; -import type mongoose from "mongoose"; -import { Types } from "mongoose"; -import { connect, disconnect } from "../../helpers/db"; - -import { getUserTagAncestors as getUserTagAncestorsResolver } from "../../../src/resolvers/Query/getUserTagAncestors"; -import type { QueryGetUserTagAncestorsArgs } from "../../../src/types/generatedGraphQLTypes"; -import { beforeAll, afterAll, describe, it, expect, vi } from "vitest"; -import { - createTwoLevelTagsWithOrg, - type TestUserTagType, -} from "../../helpers/tags"; -import { TAG_NOT_FOUND } from "../../../src/constants"; - -let MONGOOSE_INSTANCE: typeof mongoose; - -let testTag: TestUserTagType; -let testSubTag1: TestUserTagType; - -beforeAll(async () => { - MONGOOSE_INSTANCE = await connect(); - [, , [testTag, testSubTag1]] = await createTwoLevelTagsWithOrg(); -}); - -afterAll(async () => { - await disconnect(MONGOOSE_INSTANCE); -}); - -describe("resolvers -> Query -> getUserTagAncestors", () => { - it(`throws NotFoundError if no userTag exists with _id === args.id`, async () => { - const { requestContext } = await import("../../../src/libraries"); - - const spy = vi - .spyOn(requestContext, "translate") - .mockImplementationOnce((message) => `Translated ${message}`); - - try { - const args: QueryGetUserTagAncestorsArgs = { - id: new Types.ObjectId().toString(), - }; - - await getUserTagAncestorsResolver?.({}, args, {}); - } catch (error: unknown) { - expect(spy).toHaveBeenLastCalledWith(TAG_NOT_FOUND.MESSAGE); - expect((error as Error).message).toEqual( - `Translated ${TAG_NOT_FOUND.MESSAGE}`, - ); - } - }); - - it(`returns the list of all the ancestor tags for a tag with _id === args.id`, async () => { - const args: QueryGetUserTagAncestorsArgs = { - id: testSubTag1?._id.toString() ?? "", - }; - - const getUserTagAncestorsPayload = await getUserTagAncestorsResolver?.( - {}, - args, - {}, - ); - - expect(getUserTagAncestorsPayload).toEqual([testTag, testSubTag1]); - }); -});