Skip to content

BE30: Complete user preferences and settings backend#250

Merged
TienNguyen3711 merged 4 commits into
masterfrom
feature/BE30-user-preferences-refinement
May 12, 2026
Merged

BE30: Complete user preferences and settings backend#250
TienNguyen3711 merged 4 commits 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.

vicheachin1688 and others added 3 commits May 12, 2026 12:58
Merge master into feature/BE30-user-preferences-refinement:
- Keep master's pinned dependency versions for stability
- Add new packages from feature branch (axios, crypto-js, ioredis,
  lodash, moment, morgan, node-cron, passport, sharp, socket.io,
  stripe, supabase, uuid)
- Fix duplicate fs-extra entry
- Move sinon to devDependencies (correct categorisation)
- Regenerate package-lock.json
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.

I have checked and tested on my device. It works well. Approved

@TienNguyen3711 TienNguyen3711 merged commit 348a70b into master May 12, 2026
9 checks passed
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