Real-Dev-Squad / website-backend

The backend code for all our website-related apps
https://api.realdevsquad.com/
MIT License
55 stars 258 forks source link

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

Open VinuB-Dev opened 2 days ago

VinuB-Dev commented 2 days ago

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

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

Severity/Priority

Additional Information

Checklist