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

Refactor getUsers Controller to Avoid Tight Coupling with Query Parameters #2274

Open
6 of 10 tasks
VinuB-Dev opened this issue Nov 29, 2024 · 0 comments
Open
6 of 10 tasks

Comments

@VinuB-Dev
Copy link
Contributor

Issue Description

The current implementation of the getUsers function in the users controller tightly couples business logic with query parameters, such as directly using req.query.departed, req.query.dev, req.query.profile, etc., within the business logic. This approach reduces maintainability, makes the code harder to test, and introduces potential issues when adding new query parameters in the future.

To resolve this, the query parameters should be transformed and validated before being passed to services or models. This will decouple the query parameter handling from the core business logic, creating a cleaner and more modular design. Refactoring in this way will also improve the flexibility of the system, making it easier to extend or modify in the future while enhancing testability.

Expected Behavior

  • Refactor the getUsers function to decouple query parameters from business logic.
  • Ensure that query parameters (e.g., departed, dev, profile) are transformed and validated before passing them into services or models.
  • Introduce a validation layer that processes query parameters and passes them in a consistent format to the service layer.
  • The refactor should be applied consistently across the getUsers function to set a good precedent for future code development and maintainability.

Current Behavior

Currently, the getUsers function relies directly on req.query for parameters like departed, dev, and profile, which introduces tight coupling between the API handler and the request object. This approach makes the code harder to maintain, extend, and test, especially as more query parameters are added in the future.

Reproducibility

  • This issue is reproducible
  • This issue is not reproducible

Severity/Priority

  • Critical
  • High
  • Medium
  • Low

Additional Information

  • The proposed refactor will improve maintainability and promote better separation of concerns.
  • By reducing direct dependencies on query parameters, the system will be more robust to future changes and less prone to bugs related to query handling.
  • The existing code structure with direct use of req.query is prone to confusion and errors, which this change aims to prevent.

Checklist

  • I have read and followed the project's code of conduct.
  • I have searched for similar issues before creating this one.
  • I have provided all the necessary information to understand and reproduce the issue.
  • I am willing to contribute to the resolution of this issue.
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

No branches or pull requests

1 participant