Fix: Create or update notification settings to avoid error when settings doesn’t exist #658
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR ensures that notification settings are created automatically if they don’t already exist when a user attempts to update them. Previously, users without existing notification preferences faced issues updating settings.
Now, when a
PATCH
request is sent to/api/v1/settings/notification-settings
, the system checks if a notification preference exists for the user. If none exists, a new record is created before applying the update.Related Issue (Link to Github issue)
Closes #657
Steps to Reproduce:
Send a
PATCH
request to/api/v1/settings/notification-settings
with a valid JSON body as shown below, for a user who has no existing notification settings:Observe that the request fails because the application does not create notification settings for users who do not already have them.
As a result, users without existing notification settings receive an error instead of having default settings created automatically.
This bug prevents users from updating their notification preferences unless their settings already exist in the database.
Fix: Bug in Updating Notification Settings #657
Motivation and Context
This change is required to ensure that users who have not previously set their notification preferences can still update them without encountering errors. Previously, the system expected existing settings, preventing new users from modifying their preferences. This fix allows the system to create default settings if none exist, ensuring a seamless user experience.
How Has This Been Tested?
it_creates_settings_if_none_exist
inUpdateNotificationPreferenceTest.php
to verify that notification settings are created when a user attempts to update settings for the first time.PATCH
request to/api/v1/settings/notification-settings
with valid notification settings for a user without existing preferences.
Types of changes
Checklist: