Skip to content

Commit

Permalink
list tags assigned to a user on it's profile
Browse files Browse the repository at this point in the history
  • Loading branch information
meetulr committed Oct 21, 2024
1 parent 47a9749 commit cc4c06e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/resolvers/User/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { UserResolvers } from "../../types/generatedGraphQLTypes";
// import { tagsAssignedWith } from "./tagsAssignedWith";
import { posts } from "./posts";
import { tagsAssigned } from "./tagsAssigned";

export const User: UserResolvers = {
// tagsAssignedWith,
posts,
tagsAssigned,
};
31 changes: 31 additions & 0 deletions src/resolvers/User/tagsAssigned.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ActionItemCategory, OrganizationTagUser, TagUser } from "../../models";
import type {
OrganizationResolvers,
UserResolvers,
} from "../../types/generatedGraphQLTypes";

/**
* Resolver function for the `actionItemCategories` field of an `Organization`.
*
* This function retrieves the action item categories related to a specific organization.
*
* @param parent - The parent object representing the organization. It contains information about the organization, including the ID of the organization.
* @returns A promise that resolves to the action item category documents found in the database. These documents represent the action item categories related to the organization.
*
* @see ActionItemCategory - The ActionItemCategory model used to interact with the action item categories collection in the database.
* @see OrganizationResolvers - The type definition for the resolvers of the Organization fields.
*
*/
export const tagsAssigned: UserResolvers["tagsAssigned"] = async (parent) => {
const tags = await TagUser.find({
userId: parent._id,
}).lean();

const tagIds = tags.map((tag) => tag.tagId);

return await OrganizationTagUser.find({
_id: { $in: tagIds },
})
.sort({ _id: -1 })
.lean();
};
1 change: 1 addition & 0 deletions src/typeDefs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ export const types = gql`
last: PositiveInt
organizationId: ID
): UserTagsConnection
tagsAssigned: [UserTag]
updatedAt: DateTime!
}
type AppUserProfile {
Expand Down
16 changes: 2 additions & 14 deletions src/types/generatedGraphQLTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1251,8 +1251,6 @@ export type Mutation = {
removeEventVolunteer: EventVolunteer;
removeEventVolunteerGroup: EventVolunteerGroup;
removeFromUserTags?: Maybe<UserTag>;
removeFund: Fund;
removeFundraisingCampaign: FundraisingCampaign;
removeFundraisingCampaignPledge: FundraisingCampaignPledge;
removeGroupChat: GroupChat;
removeMember: Organization;
Expand Down Expand Up @@ -1718,16 +1716,6 @@ export type MutationRemoveFromUserTagsArgs = {
};


export type MutationRemoveFundArgs = {
id: Scalars['ID']['input'];
};


export type MutationRemoveFundraisingCampaignArgs = {
id: Scalars['ID']['input'];
};


export type MutationRemoveFundraisingCampaignPledgeArgs = {
id: Scalars['ID']['input'];
};
Expand Down Expand Up @@ -3003,6 +2991,7 @@ export type User = {
pluginCreationAllowed: Scalars['Boolean']['output'];
posts?: Maybe<PostsConnection>;
registeredEvents?: Maybe<Array<Maybe<Event>>>;
tagsAssigned?: Maybe<Array<Maybe<UserTag>>>;
tagsAssignedWith?: Maybe<UserTagsConnection>;
updatedAt: Scalars['DateTime']['output'];
};
Expand Down Expand Up @@ -4455,8 +4444,6 @@ export type MutationResolvers<ContextType = any, ParentType extends ResolversPar
removeEventVolunteer?: Resolver<ResolversTypes['EventVolunteer'], ParentType, ContextType, RequireFields<MutationRemoveEventVolunteerArgs, 'id'>>;
removeEventVolunteerGroup?: Resolver<ResolversTypes['EventVolunteerGroup'], ParentType, ContextType, RequireFields<MutationRemoveEventVolunteerGroupArgs, 'id'>>;
removeFromUserTags?: Resolver<Maybe<ResolversTypes['UserTag']>, ParentType, ContextType, RequireFields<MutationRemoveFromUserTagsArgs, 'input'>>;
removeFund?: Resolver<ResolversTypes['Fund'], ParentType, ContextType, RequireFields<MutationRemoveFundArgs, 'id'>>;
removeFundraisingCampaign?: Resolver<ResolversTypes['FundraisingCampaign'], ParentType, ContextType, RequireFields<MutationRemoveFundraisingCampaignArgs, 'id'>>;
removeFundraisingCampaignPledge?: Resolver<ResolversTypes['FundraisingCampaignPledge'], ParentType, ContextType, RequireFields<MutationRemoveFundraisingCampaignPledgeArgs, 'id'>>;
removeGroupChat?: Resolver<ResolversTypes['GroupChat'], ParentType, ContextType, RequireFields<MutationRemoveGroupChatArgs, 'chatId'>>;
removeMember?: Resolver<ResolversTypes['Organization'], ParentType, ContextType, RequireFields<MutationRemoveMemberArgs, 'data'>>;
Expand Down Expand Up @@ -4810,6 +4797,7 @@ export type UserResolvers<ContextType = any, ParentType extends ResolversParentT
pluginCreationAllowed?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType>;
posts?: Resolver<Maybe<ResolversTypes['PostsConnection']>, ParentType, ContextType, Partial<UserPostsArgs>>;
registeredEvents?: Resolver<Maybe<Array<Maybe<ResolversTypes['Event']>>>, ParentType, ContextType>;
tagsAssigned?: Resolver<Maybe<Array<Maybe<ResolversTypes['UserTag']>>>, ParentType, ContextType>;
tagsAssignedWith?: Resolver<Maybe<ResolversTypes['UserTagsConnection']>, ParentType, ContextType, Partial<UserTagsAssignedWithArgs>>;
updatedAt?: Resolver<ResolversTypes['DateTime'], ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
Expand Down

0 comments on commit cc4c06e

Please sign in to comment.