-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add limit on returning number of spaces on dashboard; retrieve invitations as count #4907
base: develop
Are you sure you want to change the base?
Conversation
WalkthroughThis pull request adds a new resolver method, Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client
participant Resolver as MeResolverFields
participant Service as MeService
participant Roles as RolesService
Client->>Resolver: Query communityInvitationsCount(agentInfo, states)
Resolver->>Resolver: Validate agentInfo (throw exception if userID is empty)
Resolver->>Service: getCommunityInvitationsCountForUser(userId, states)
Service->>Roles: getCommunityInvitationsForUser(userId, states)
Roles-->>Service: Return invitation list
Service-->>Resolver: Return invitation count
Resolver-->>Client: Return count result
sequenceDiagram
participant Client as Client
participant Resolver as MeResolverFields
participant Service as MeService
Client->>Resolver: Query spaceMembershipsHierarchical(agentInfo, limit)
Resolver->>Service: getCommunityMembershipsHierarchical(agentInfo, limit)
Service-->>Resolver: Return limited hierarchical spaces
Resolver-->>Client: Return memberships result
Possibly related PRs
Suggested reviewers
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (2)
src/services/api/me/me.resolver.fields.ts (1)
58-83
: Add input validation for states array.While the userID validation is good, consider adding validation for the states array to ensure it contains valid state values.
public async communityInvitationsCount( @CurrentUser() agentInfo: AgentInfo, @Args({ name: 'states', nullable: true, type: () => [String], description: 'The state names you want to filter on', }) states: string[] ): Promise<number> { if (agentInfo.userID === '') { throw new ValidationException( 'Unable to retrieve invitations as no userID provided.', LogContext.COMMUNITY ); } + if (states?.length > 0) { + const validStates = ['pending', 'accepted', 'rejected']; // Add your valid states here + const invalidStates = states.filter(state => !validStates.includes(state)); + if (invalidStates.length > 0) { + throw new ValidationException( + `Invalid states provided: ${invalidStates.join(', ')}`, + LogContext.COMMUNITY + ); + } + } return this.meService.getCommunityInvitationsCountForUser( agentInfo.userID, states ); }src/services/api/me/me.service.ts (1)
185-198
: Use immutable array operations for limiting spaces.The current implementation modifies the original array using splice. Consider using slice instead to avoid potential side effects.
const levelZeroSpacesRaw = this.filterSpacesByLevel( sortedFlatListSpacesWithMembership, SpaceLevel.L0 ); + const limitedLevelZeroSpaces = limit + ? levelZeroSpacesRaw.slice(0, limit) + : levelZeroSpacesRaw; - if (limit) { - levelZeroSpacesRaw.splice(limit); - }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/services/api/me/me.resolver.fields.ts
(2 hunks)src/services/api/me/me.service.ts
(3 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/services/api/me/me.resolver.fields.ts (1)
Pattern src/**/*.{ts,js}
: Review the TypeScript/JavaScript code for NestJS best practices, dependency injection, module structure, and potential bugs.
Context Files (Do Not Review):
docs/Design.md
- Design overview of the projectdocs/Pagination.md
- Pagination design overviewdocs/Developing.md
- Development setup overviewdocs/graphql-typeorm-usage.md
- overview of GraphQL and TypeORM usage and how they are used together with NestJS in the projectdocs/database-definitions.md
- guidelines for creating TypeORM entity defnitionssrc/core/error-handling/graphql.exception.filter.ts
- GraphQL error handlingsrc/core/error-handling/http.exception.filter.ts
- HTTP error handlingsrc/core/error-handling/rest.error.response.ts
- REST error responsesrc/core/error-handling/unhandled.exception.filter.ts
- Global exception handler
Guidelines:
- Our project uses global exception handlers (
UnhandledExceptionFilter
), so avoid suggesting additionaltry/catch
blocks unless handling specific cases. - Use NestJS latest documentation from
https://docs.nestjs.com/
for reference on NestJS best practices. - Use TypeORM latest documentation from
https://typeorm.io/
for reference on TypeORM best practices. - Refer to the design overview in the context files for better understanding.
src/services/api/me/me.service.ts (1)
Pattern src/**/*.{ts,js}
: Review the TypeScript/JavaScript code for NestJS best practices, dependency injection, module structure, and potential bugs.
Context Files (Do Not Review):
docs/Design.md
- Design overview of the projectdocs/Pagination.md
- Pagination design overviewdocs/Developing.md
- Development setup overviewdocs/graphql-typeorm-usage.md
- overview of GraphQL and TypeORM usage and how they are used together with NestJS in the projectdocs/database-definitions.md
- guidelines for creating TypeORM entity defnitionssrc/core/error-handling/graphql.exception.filter.ts
- GraphQL error handlingsrc/core/error-handling/http.exception.filter.ts
- HTTP error handlingsrc/core/error-handling/rest.error.response.ts
- REST error responsesrc/core/error-handling/unhandled.exception.filter.ts
- Global exception handler
Guidelines:
- Our project uses global exception handlers (
UnhandledExceptionFilter
), so avoid suggesting additionaltry/catch
blocks unless handling specific cases. - Use NestJS latest documentation from
https://docs.nestjs.com/
for reference on NestJS best practices. - Use TypeORM latest documentation from
https://typeorm.io/
for reference on TypeORM best practices. - Refer to the design overview in the context files for better understanding.
public async getCommunityInvitationsCountForUser( | ||
userId: string, | ||
states?: string[] | ||
): Promise<number> { | ||
const invitations = await this.rolesService.getCommunityInvitationsForUser( | ||
userId, | ||
states | ||
); | ||
return invitations.length; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Optimize count retrieval for better performance.
The current implementation fetches all invitations just to get the count. Consider adding a dedicated count method in rolesService
to avoid fetching unnecessary data.
public async getCommunityInvitationsCountForUser(
userId: string,
states?: string[]
): Promise<number> {
- const invitations = await this.rolesService.getCommunityInvitationsForUser(
+ return this.rolesService.getCommunityInvitationsCountForUser(
userId,
states
);
- return invitations.length;
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
public async getCommunityInvitationsCountForUser( | |
userId: string, | |
states?: string[] | |
): Promise<number> { | |
const invitations = await this.rolesService.getCommunityInvitationsForUser( | |
userId, | |
states | |
); | |
return invitations.length; | |
} | |
public async getCommunityInvitationsCountForUser( | |
userId: string, | |
states?: string[] | |
): Promise<number> { | |
return this.rolesService.getCommunityInvitationsCountForUser( | |
userId, | |
states | |
); | |
} |
Summary by CodeRabbit