RealDevSquad / RealDevSquad/website-backend
Refactor getUsers Controller to Avoid Tight Coupling with Query Parameters
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 74
- Forks
- 276
- Avg merge
- 1d 26m
- Merged PRs (30d)
- 14
Description
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
getUsersfunction 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
getUsersfunction 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the getUsers controller and tracing how req.query.departed, req.query.dev, and req.query.profile flow into services or models. Define the validation and transformation boundary before changing the handler; done means the controller passes a consistent validated format and no longer couples business logic directly to request query parameters.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- api, backend
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100