Skip to content

fixing some functions for the dashboard page#21

Merged
tarek-gritli merged 2 commits intomainfrom
racem
Jun 8, 2025
Merged

fixing some functions for the dashboard page#21
tarek-gritli merged 2 commits intomainfrom
racem

Conversation

@racemkchaou
Copy link
Contributor

@racemkchaou racemkchaou commented Jun 8, 2025

PR Type

Enhancement


Description

  • Added endpoints to retrieve total counts for plants and posts.

  • Introduced endpoint and service for fetching upcoming tasks.

  • Enhanced controllers and services with new data retrieval methods.


Changes walkthrough 📝

Relevant files
Enhancement
plant.controller.ts
Add endpoint to get total plant count for user                     

src/plant/plant.controller.ts

  • Added GET /count endpoint to return total plant count for user's farm.
  • Documented new endpoint with Swagger decorators.
  • +8/-0     
    plant.service.ts
    Add service method to count user's farm plants                     

    src/plant/plant.service.ts

  • Implemented getPlantCount method to count plants for a user's farm.
  • +9/-0     
    posts.controller.ts
    Add endpoint to get total posts count                                       

    src/posts/posts.controller.ts

    • Added GET /count endpoint to return total number of posts.
    +7/-0     
    posts.service.ts
    Add service method to count all posts                                       

    src/posts/posts.service.ts

    • Implemented getTotalPostsCount method to count all forum posts.
    +6/-0     
    tasks.controller.ts
    Add endpoint to fetch upcoming tasks                                         

    src/tasks/tasks.controller.ts

  • Added GET /upcoming endpoint to fetch upcoming tasks (PENDING or
    IN_PROGRESS).
  • Documented new endpoint with Swagger decorators.
  • +7/-0     
    tasks.service.ts
    Add service method for upcoming tasks retrieval                   

    src/tasks/tasks.service.ts

  • Implemented getUpcomingTasks method to retrieve tasks with PENDING or
    IN_PROGRESS status.
  • Included error handling for the new method.
  • +17/-0   

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • @qodo-code-review
    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Code Indentation

    The getPlantCount method has inconsistent indentation compared to other methods in the file, which could affect code readability and maintainability.

      async getPlantCount(userId: number): Promise<number> {
      const farm = await this.farmService.getFarmByUserId(userId);
      const count = await this.prisma.plant.count({
        where: { farm_id: farm.id },
      });
      return count;
    }
    Missing Authentication

    The getTotalPostsCount endpoint doesn't appear to have authentication decorators, unlike other endpoints. This could potentially expose post count data to unauthenticated users.

    @Get('count')
    getTotalPostsCount() {
      return this.postsService.getTotalPostsCount();
    }
    Missing Filtering

    The getTotalPostsCount method returns all forum posts without filtering by visibility or user permissions, which might expose counts of private posts.

    async getTotalPostsCount() {
      return this.prisma.forumPost.count();
    }

    @github-actions
    Copy link

    github-actions bot commented Jun 8, 2025

    Failed to generate code suggestions for PR

    @qodo-code-review
    Copy link

    qodo-code-review bot commented Jun 8, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Add error handling

    Add error handling to handle cases where farm lookup fails or database
    operations encounter issues. This prevents unhandled exceptions from propagating
    to the controller.

    src/plant/plant.service.ts [43-49]

     async getPlantCount(userId: number): Promise<number> {
    -const farm = await this.farmService.getFarmByUserId(userId);
    -const count = await this.prisma.plant.count({
    -  where: { farm_id: farm.id },
    -});
    -return count;
    +try {
    +  const farm = await this.farmService.getFarmByUserId(userId);
    +  const count = await this.prisma.plant.count({
    +    where: { farm_id: farm.id },
    +  });
    +  return count;
    +} catch (error) {
    +  throw new InternalServerErrorException(error, 'Failed to retrieve plant count');
    +}
     }
    • Apply / Chat
    Suggestion importance[1-10]: 6

    __

    Why: The suggestion correctly identifies inconsistency with error handling patterns used elsewhere in the PR (like getUpcomingTasks method) and adds appropriate exception handling for robustness.

    Low
    General
    Add API documentation

    Add Swagger documentation decorators to the endpoint for consistency with other
    endpoints and to provide API documentation for the count endpoint.

    src/posts/posts.controller.ts [159-162]

     @Get('count')
    +@ApiOperation({ summary: 'Get total number of posts' })
    +@ApiResponse({ status: 200, description: 'Total posts count returned' })
     getTotalPostsCount() {
       return this.postsService.getTotalPostsCount();
     }
    • Apply / Chat
    Suggestion importance[1-10]: 4

    __

    Why: The suggestion correctly identifies missing Swagger decorators for consistency, as other new endpoints in the PR include @ApiOperation and @ApiResponse decorators.

    Low
    • Update

    @tarek-gritli tarek-gritli merged commit 9479429 into main Jun 8, 2025
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    2 participants