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

fix: update base condition for findAll() #359

Merged
merged 1 commit into from
Nov 14, 2024
Merged

Conversation

kshitij-k-osmosys
Copy link
Contributor

@kshitij-k-osmosys kshitij-k-osmosys commented Nov 6, 2024

API PR Checklist

Pre-requisites

  • I have gone through the Contributing guidelines for Submitting a Pull Request (PR) and ensured that this is not a duplicate PR.
  • I have performed unit testing for the new feature added or updated to ensure the new features added are working as expected.
  • I have added/updated test cases to the test suite as applicable.
  • I have performed preliminary testing using the test suite to ensure that any existing features are not impacted and any new features are working as expected as a whole.
  • I have added/updated the required api docs as applicable.
  • I have added/updated the .env.example file with the required values as applicable.

PR Details

PR details have been updated as per the given format (see below)

  • PR title adheres to the format specified in guidelines (e.g., feat: add admin login endpoint)
  • Description has been added
  • Related changes have been added (optional)
  • Screenshots have been added (optional)
  • Query request and response examples have been added (as applicable, in case added or updated)
  • Documentation changes have been listed (as applicable)
  • Test suite/unit testing output is added (as applicable)
  • Pending actions have been added (optional)
  • Any other additional notes have been added (optional)

Additional Information

  • Appropriate label(s) have been added (ready for review should be added if the PR is ready to be reviewed)
  • Assignee(s) and reviewer(s) have been added (optional)

Note: Reviewer should ensure that the checklist and description have been populated and followed correctly, and the PR should be merged only after resolving all conversations and verifying that CI checks pass.


Description:

Update baseConditions for graphql core helper function findAll() to fetch active status records

Summary by CodeRabbit

  • New Features
    • Enhanced filtering for applications and providers to only include those with an active status in the retrieval processes.
  • Bug Fixes
    • Maintained existing error handling and control flow for user-related queries.

Copy link

coderabbitai bot commented Nov 6, 2024

Walkthrough

The changes involve modifications to the ApplicationsService and ProvidersService classes in their respective service files. Both services have updated their getAllApplications and getAllProviders methods to include a new condition in the baseConditions array, specifically filtering for active status applications and providers. No other methods or functionalities were altered, and there were no changes to the declarations of exported or public entities.

Changes

File Path Change Summary
apps/api/src/modules/applications/applications.service.ts Updated getAllApplications to filter by { field: 'status', value: Status.ACTIVE }.
apps/api/src/modules/providers/providers.service.ts Updated getAllProviders to filter by { field: 'status', value: Status.ACTIVE }.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ApplicationsService
    participant ProvidersService

    User->>ApplicationsService: Request all applications
    ApplicationsService->>Database: Query applications with status ACTIVE
    Database-->>ApplicationsService: Return active applications
    ApplicationsService-->>User: Send active applications

    User->>ProvidersService: Request all providers
    ProvidersService->>Database: Query providers with status ACTIVE
    Database-->>ProvidersService: Return active providers
    ProvidersService-->>User: Send active providers
Loading

🐰 "In fields of green where bunnies play,
We've filtered apps and providers today.
Only the active, bright and spry,
Hop into queries, oh me, oh my!
With each little change, we dance and cheer,
For a world of status, so crystal clear!" 🌼


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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

Copy link

@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 (2)
apps/api/src/modules/applications/applications.service.ts (1)

Line range hint 62-68: Consider moving status filtering to CoreService.

Since status filtering is a common requirement (as evidenced by similar changes in ProvidersService), consider making this a configurable feature in CoreService. This would:

  • Reduce code duplication
  • Provide consistent status filtering across all services
  • Make it easier to modify status filtering behavior globally

You could modify CoreService to accept status filtering configuration in its constructor or add a method to configure default conditions that apply to all findAll calls.

Example approach:

export class CoreService<T> {
  protected defaultConditions: Array<{field: string; value: any}> = [];

  setDefaultConditions(conditions: Array<{field: string; value: any}>) {
    this.defaultConditions = conditions;
  }

  async findAll(options, entity, searchableFields, additionalConditions = []) {
    const conditions = [...this.defaultConditions, ...additionalConditions];
    // existing implementation
  }
}
apps/api/src/modules/providers/providers.service.ts (1)

Line range hint 66-71: Consider adding a comment about the status filtering behavior.

Since status filtering is a consistent pattern across methods in this service, it would be helpful to document this behavior.

+    // Always filter for active providers to maintain consistency with getById and getConfigById
     const baseConditions = [{ field: 'status', value: Status.ACTIVE }];
     const searchableFields = ['name'];
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3a54511 and 6b8a7d2.

📒 Files selected for processing (2)
  • apps/api/src/modules/applications/applications.service.ts (1 hunks)
  • apps/api/src/modules/providers/providers.service.ts (1 hunks)
🔇 Additional comments (4)
apps/api/src/modules/applications/applications.service.ts (2)

62-62: LGTM! The base condition implementation is consistent.

The addition of Status.ACTIVE filter in baseConditions aligns with the existing pattern used in findById and findByUserId methods.


Line range hint 62-68: Verify impact on existing getAllApplications consumers.

While the change maintains consistency with other methods, let's verify that no existing code relies on retrieving non-active applications through getAllApplications.

✅ Verification successful

Let me gather more information about the implementation details to better understand the impact.


Let me check one more aspect to see if there are any GraphQL queries or fragments that might be affected by this change.


Based on the gathered information, I can now provide a final response:

Change to filter active applications appears safe to proceed

The implementation shows that getAllApplications is only used in the resolver as a direct pass-through to the service method, with no other direct consumers in the codebase. The new filter for active applications is consistent with standard patterns and doesn't show any evidence of breaking existing functionality.

  • The only usage is in applications.resolver.ts which simply forwards the call to the service
  • The service implementation adds a base condition for active status, which is a common pattern
  • No test files were found that might rely on retrieving non-active applications
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for getAllApplications usage to verify impact
echo "Searching for getAllApplications usage patterns..."
rg -l "getAllApplications" --type ts

# Search for any explicit status handling in GraphQL resolvers
echo "Checking for status handling in resolvers..."
ast-grep --pattern 'class $_ extends $_ {
  $$$
  getAllApplications($_, $_) {
    $$$
  }
  $$$
}'

Length of output: 465


Script:

#!/bin/bash
# Check the implementation of getAllApplications in resolver and service
echo "Checking applications resolver implementation..."
rg -A 10 "getAllApplications" apps/api/src/modules/applications/applications.resolver.ts

echo "Checking applications service implementation..."
rg -A 10 "getAllApplications" apps/api/src/modules/applications/applications.service.ts

# Check for any direct status filtering in queries
echo "Checking for status-related queries..."
rg -A 5 "status.*=.*Status" apps/api/src/modules/applications/

Length of output: 1028


Script:

#!/bin/bash
# Search for GraphQL queries and fragments related to applications
echo "Checking GraphQL queries and fragments..."
fd -e graphql . | xargs rg -A 5 "applications.*{" 

# Check for any test files that might rely on non-active applications
echo "Checking test files..."
fd -e spec.ts -e test.ts . | xargs rg -A 5 "getAllApplications"

Length of output: 357

apps/api/src/modules/providers/providers.service.ts (2)

Line range hint 66-71: Implementation is performant.

The status filter is correctly implemented at the database query level through baseConditions, ensuring efficient filtering.


66-66: LGTM! The change aligns with the PR objectives.

The addition of the status filter in baseConditions ensures that only active providers are fetched, which is consistent with the PR's goal.

Let's verify the consistency of this pattern across other services:

✅ Verification successful

The Status.ACTIVE filter pattern is consistently implemented across relevant services

The verification shows that:

  • The Status import is properly defined from 'src/common/constants/database'
  • The same baseConditions pattern with Status.ACTIVE is consistently used in related services:
    • applications.service.ts
    • providers.service.ts
    • server-api-keys.service.ts
    • notifications.service.ts

This confirms that the implementation follows the established pattern across the codebase and maintains consistency with other services that require active status filtering.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if other services follow the same pattern for status filtering
# Expected: Similar baseConditions usage in other service files

# Search for similar findAll implementations in service files
rg -A 5 "baseConditions.*Status\.ACTIVE" "apps/api/src/modules/**/*service.ts"

# Search for any potential inconsistencies in status filtering
ast-grep --pattern 'findAll($$$, $_, $_, baseConditions)'

Length of output: 216


Script:

#!/bin/bash
# Let's try a more precise search approach

# 1. First, let's find all service files
fd "service.ts$" apps/api/src/modules/

# 2. Then search for baseConditions pattern with proper context
rg -l "baseConditions.*=.*\[.*Status\.ACTIVE" apps/api/src/modules/

# 3. Let's also verify the Status import
rg "import.*Status" apps/api/src/modules/

# 4. Search for similar findAll implementations
rg "findAll.*baseConditions" apps/api/src/modules/ -A 2

Length of output: 3375

@xixas xixas merged commit 305cdb1 into main Nov 14, 2024
6 checks passed
@xixas xixas deleted the fix/findall-base-condition branch November 14, 2024 07:49
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