Skip to content

BE30: Complete user preferences and settings backend#250

Open
vicheachin1688 wants to merge 1 commit into
masterfrom
feature/BE30-user-preferences-refinement
Open

BE30: Complete user preferences and settings backend#250
vicheachin1688 wants to merge 1 commit into
masterfrom
feature/BE30-user-preferences-refinement

Conversation

@vicheachin1688
Copy link
Copy Markdown
Collaborator

This PR completes the backend implementation for BE30. The primary focus was fixing a critical data loss bug where partial updates to user settings would unintentionally wipe out unrelated preference groups.

Key changes:

Fixed the persistence logic in updateUserPreferences.js. The system now correctly merges updates for health context, food preferences, and notification settings rather than overwriting them. This means changing a UI theme will no longer delete your food allergies.
Added full support for UI settings. We implemented new GET and PUT endpoints for /api/user/preferences/extended/ui-settings to handle theme, language, and font size preferences.
Standardized API responses. All modified endpoints now return a consistent JSON envelope containing success, data, and contractVersion fields.
Strengthened validation. We added comprehensive checks in the validator for nested payloads, specific notification flags, and UI setting values to prevent malformed data from reaching the database.
Verified with 27 automated tests. We updated the unit and integration test suites to specifically cover partial update safety, nested payload persistence, and error handling for invalid inputs.
Endpoints updated or added:

GET and PUT /api/user/preferences/extended
GET and PUT /api/user/preferences/extended/notifications
GET and PUT /api/user/preferences/extended/ui-settings
Total tests passing for BE30 scope: 27 passing, 0 failing.

- Fix partial update data loss bug in updateUserPreferences.js
- Add UI settings endpoints (GET/PUT /preferences/extended/ui-settings)
- Standardize extended preferences API contract to v3
- Add validateExtendedUserPreferences and validateUiSettings validators
- Support canonical nested food_preferences payload
- Merge notification_preferences instead of overwriting
- Add/update unit and integration test coverage (27 passing)
Copy link
Copy Markdown
Collaborator

@TienNguyen3711 TienNguyen3711 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a quick follow-up before merge:

  • food_preferences.allergies and food_preferences.health_conditions are accepted by validation but are not applied in updateUserPreferences, so the API can return success while silently ignoring those fields.
  • Nested preference refs should require positive integer id / referenceId; right now invalid values can pass validation and then get dropped by the model.
  • The notification preferences response shape changed to data.notification_preferences; please confirm this contract change is intentional and that existing consumers are updated.

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

Successfully merging this pull request may close these issues.

2 participants