-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// notificationSettings.js | ||
|
||
class NotificationSettings { | ||
constructor(userId) { | ||
this.userId = userId; | ||
this.preferences = { | ||
email: true, | ||
sms: false, | ||
push: true, | ||
newsletter: true, | ||
}; | ||
} | ||
|
||
// Get current notification preferences | ||
getPreferences() { | ||
return this.preferences; | ||
} | ||
|
||
// Update notification preferences | ||
updatePreferences(newPreferences) { | ||
this.preferences = { ...this.preferences, ...newPreferences }; | ||
console.log(`Notification preferences updated for user ${this.userId}:`, this.preferences); | ||
} | ||
|
||
// Reset to default preferences | ||
resetToDefault() { | ||
this.preferences = { | ||
email: true, | ||
sms: false, | ||
push: true, | ||
newsletter: true, | ||
}; | ||
console.log(`Notification preferences reset to default for user ${this.userId}.`); | ||
} | ||
} | ||
|
||
// Example usage | ||
const userNotificationSettings = new NotificationSettings('user123'); | ||
console.log('Current Preferences:', userNotificationSettings.getPreferences()); | ||
|
||
userNotificationSettings.updatePreferences({ sms: true, newsletter: false }); | ||
console.log('Updated Preferences:', userNotificationSettings.getPreferences()); | ||
|
||
userNotificationSettings.resetToDefault(); | ||
console.log('Preferences after reset:', userNotificationSettings.getPreferences()); |