airqo-platform / airqo-platform/AirQo-api
Refactor: Move default ID assignment logic from controllers to utility layer
- Ngôn ngữ chính
- JavaScript
- Star
- 26
- Fork
- 24
- Merge trung bình
- 5 giờ 36 phút
- Pull request đã merge (30 ngày)
- 81
Mô tả
## Problem
In the preference controller, default group/network ID assignment is done directly in the controller methods, creating tight coupling with configuration constants.
**Affected locations:**
- Lines 1048-1050 (getUserDefaultGroupTheme)
- Lines 1088-1090 (updateUserDefaultGroupTheme)
- Lines 1204-1206 (getUserDefaultNetworkTheme)
- Lines 1244-1246 (updateUserDefaultNetworkTheme)
**Current implementation:**
```javascript
// Set default group ID
request.params.group_id = constants.DEFAULT_GROUP;
const result = await preferenceUtil.getUserGroupTheme(request, next);
```
## Proposed Solution
Move the default ID assignment logic into the utility layer to improve modularity and reduce coupling:
1. Create dedicated utility methods for default contexts (e.g., `getUserDefaultGroupTheme`, `getUserDefaultNetworkTheme`)
2. Or enhance existing utility methods to handle default values internally
3. Replace direct assignments in controllers with calls to these utility functions
## Benefits
- Reduces coupling between controllers and configuration constants
- Centralizes default value logic in one place
- Improves maintainability and testability
## References
- PR: https://github.com/airqo-platform/AirQo-api/pull/4937
- Comment: https://github.com/airqo-platform/AirQo-api/pull/4937#discussion_r2212691346
Requested by: @Baalmart
Hướng dẫn đóng góp
Đánh giá
Issue này chưa được đánh giá.