Skip to content
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

[Unauth Home page] Sort Explore Spaces section on most activity #4578

Merged
merged 6 commits into from
Oct 3, 2024

Conversation

hero101
Copy link
Collaborator

@hero101 hero101 commented Oct 2, 2024

  • Added exploreSpaces(options: ExploreSpacesInput) query, which returns level 0 Spaces, sorted by the most active first in the past X days.
  • ExploreSpacesInput include
    • limit amount of Spaces to return (defaults to 30)
    • daysOld Includes only Activity in the past X days (defaults to 30)

Summary by CodeRabbit

  • New Features

    • Introduced a new query method to retrieve active spaces based on user-defined limits and activity within a specified number of days.
    • Added an input type allowing users to specify the number of spaces returned and the timeframe for activity.
  • Enhancements

    • Improved error messaging for space retrieval failures to provide clearer feedback to users.

Copy link
Contributor

coderabbitai bot commented Oct 2, 2024

Walkthrough

A new input data transfer object (DTO) named ExploreSpacesInput has been introduced for GraphQL queries. This DTO includes two fields: limit and daysOld, both with default values. Additionally, a new query method exploreSpaces has been added to the SpaceResolverQueries class, which utilizes the ExploreSpacesInput DTO to retrieve active spaces based on specified criteria. Correspondingly, a new method getExploreSpaces has been implemented in the SpaceService class to handle the logic of fetching spaces based on their activity within a given timeframe.

Changes

File Path Change Summary
src/domain/space/space/dto/explore.spaces.dto.input.ts - New class added: ExploreSpacesInput
- New field added: limit: number
- New field added: daysOld: number
src/domain/space/space/space.resolver.queries.ts - Method added: public exploreSpaces(@Args('options', { nullable: true }) options?: ExploreSpacesInput): Promise<ISpace[]>
- Import added: import { ExploreSpacesInput } from './dto/explore.spaces.dto.input';
src/domain/space/space/space.service.ts - Method added: public getExploreSpaces(limit = 30, daysOld = 30)
- Method signature updated: `async getSpaceOrFail(spaceID: string, options?: FindOneOptions): Promise<ISpace

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@hero101 hero101 requested a review from bobbykolev October 2, 2024 12:02
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (3)
src/domain/space/space/dto/explore.spaces.dto.input.ts (2)

5-10: Consider removing the non-null assertion for the limit field.

The limit field is well-defined with appropriate decorators and options. However, since the field is nullable (as indicated by the nullable: true option), the non-null assertion (!) at the end of the field declaration might not be necessary and could be misleading.

Consider changing:

limit!: number;

to:

limit?: number;

This change would more accurately reflect the nullable nature of the field.


12-17: Consider removing the non-null assertion and adding a minimum value check for the daysOld field.

The daysOld field is well-defined with appropriate decorators and options. However, there are two suggestions for improvement:

  1. Since the field is nullable (as indicated by the nullable: true option), the non-null assertion (!) at the end of the field declaration might not be necessary and could be misleading. Consider changing:

    daysOld!: number;

    to:

    daysOld?: number;
  2. It might be beneficial to add a minimum value check for daysOld to ensure it's always a positive number. This can be done using a class validator decorator, such as @Min(1) from the class-validator package.

Example implementation:

import { Min } from 'class-validator';

// ...

@Field(() => Number, {
  nullable: true,
  description: 'Take into account only the activity in the past X days.',
  defaultValue: 30,
})
@Min(1)
daysOld?: number;

These changes would more accurately reflect the nullable nature of the field and ensure that only valid values are accepted.

src/domain/space/space/space.resolver.queries.ts (1)

69-78: LGTM: New exploreSpaces query method

The exploreSpaces query method is well-implemented and aligns with the PR objectives. It correctly uses guards, decorators, and follows NestJS best practices. The method signature and implementation are appropriate for the required functionality.

However, consider adding input validation for the options parameter to ensure that limit and daysOld are within acceptable ranges before passing them to the service method.

Consider adding input validation like this:

public exploreSpaces(
  @Args('options', { nullable: true }) options?: ExploreSpacesInput
): Promise<ISpace[]> {
  const limit = options?.limit && options.limit > 0 ? options.limit : 30;
  const daysOld = options?.daysOld && options.daysOld > 0 ? options.daysOld : 30;
  return this.spaceService.getExploreSpaces(limit, daysOld);
}

This ensures that default values are used if the input is invalid or not provided.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e105203 and eb4a68e.

📒 Files selected for processing (3)
  • src/domain/space/space/dto/explore.spaces.dto.input.ts (1 hunks)
  • src/domain/space/space/space.resolver.queries.ts (2 hunks)
  • src/domain/space/space/space.service.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
src/domain/space/space/dto/explore.spaces.dto.input.ts (1)

Pattern src/**/*.{ts,js}: Review the TypeScript/JavaScript code for NestJS best practices, dependency injection, module structure, and potential bugs. Ensure that the code adheres to TypeScript's typing system and modern standards.

src/domain/space/space/space.resolver.queries.ts (1)

Pattern src/**/*.{ts,js}: Review the TypeScript/JavaScript code for NestJS best practices, dependency injection, module structure, and potential bugs. Ensure that the code adheres to TypeScript's typing system and modern standards.

src/domain/space/space/space.service.ts (1)

Pattern src/**/*.{ts,js}: Review the TypeScript/JavaScript code for NestJS best practices, dependency injection, module structure, and potential bugs. Ensure that the code adheres to TypeScript's typing system and modern standards.

🔇 Additional comments (5)
src/domain/space/space/dto/explore.spaces.dto.input.ts (2)

1-1: LGTM: Import statement is correct and concise.

The import statement correctly imports the necessary decorators from @nestjs/graphql for defining a GraphQL input type.


3-4: LGTM: Class declaration follows NestJS best practices.

The ExploreSpacesInput class is correctly decorated with @InputType() and exported, adhering to NestJS and GraphQL conventions for input DTOs.

src/domain/space/space/space.resolver.queries.ts (2)

8-8: LGTM: Import statement for ExploreSpacesInput

The import statement for ExploreSpacesInput is correctly added and follows the project's naming conventions for DTO files.


8-8: Summary: New exploreSpaces query successfully implemented

The changes in this file successfully implement the new exploreSpaces query as per the PR objectives. The new query allows for retrieving active spaces sorted by activity within a specified timeframe. The implementation follows NestJS best practices, uses proper typing, and integrates well with the existing codebase.

Key points:

  1. Correct import of the new ExploreSpacesInput DTO.
  2. Well-structured query method with appropriate guards and decorators.
  3. Proper use of the SpaceService to fetch the required data.

The only suggestion is to consider adding input validation for the options parameter to ensure robust handling of user input.

Overall, these changes effectively enhance the functionality of the Explore Spaces section as intended.

Also applies to: 69-78

src/domain/space/space/space.service.ts (1)

83-83: Importing Activity entity is necessary and correctly implemented.

src/domain/space/space/space.service.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
src/domain/space/space/space.service.ts (1)

737-756: LGTM: Well-implemented method with a suggestion.

The getExploreSpaces method is well-implemented. It correctly uses the input parameters, constructs a complex query using TypeORM's query builder, and should retrieve the desired results efficiently.

Suggestion: Consider adding a comment explaining the query logic for better maintainability, especially the join with the Activity table and the grouping/ordering logic.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between eb4a68e and 920fd23.

📒 Files selected for processing (1)
  • src/domain/space/space/space.service.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/domain/space/space/space.service.ts (1)

Pattern src/**/*.{ts,js}: Review the TypeScript/JavaScript code for NestJS best practices, dependency injection, module structure, and potential bugs. Ensure that the code adheres to TypeScript's typing system and modern standards.

🔇 Additional comments (2)
src/domain/space/space/space.service.ts (2)

83-86: LGTM: New import and constants added.

The new import of Activity and the introduction of constants EXPLORE_SPACES_LIMIT and EXPLORE_SPACES_ACTIVITY_DAYS_OLD are well-placed and will be useful for the new getExploreSpaces method.


733-736: LGTM: Well-defined method signature.

The getExploreSpaces method signature is clear and concise. It uses the newly defined constants as default values for the parameters, which is a good practice for maintainability.

@bobbykolev bobbykolev merged commit 563ceb1 into develop Oct 3, 2024
3 checks passed
@bobbykolev bobbykolev deleted the server-4517 branch October 3, 2024 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants