airqo-platform / airqo-platform/AirQo-api

Refactor: Move default ID assignment logic from controllers to utility layer

未关闭
#4,938 0 条评论 0 个 reaction 已指派 1 人 已被 @Baalmart 认领 在 GitHub 查看
主要语言
JavaScript
星标
26
派生
24
平均合并
5 小时 36 分钟
30 天内合并 PR
81

描述

## 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

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。