-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(api): Use UpdatePreference
use-case for all Subscriber Preference updates
#6889
refactor(api): Use UpdatePreference
use-case for all Subscriber Preference updates
#6889
Conversation
✅ Deploy Preview for novu-stg-vite-dashboard-poc ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
UpdatePreference
use-case for all Subscriber Preference updates
…criber-api-inbox-api
…criber-api-inbox-api
const response = await updateGlobalPreferences({}, session); | ||
|
||
expect(response.data.data.preference.channels).to.eql({}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case asserts that empty objects can be supplied when updating global preferences in relation to this UpsertPreferences
change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you will see further down, it's not ideal that we have some mapping logic in the controller
level. I decided that's a suitable approach for now as we'll be performing a Subscriber API overhaul soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bunch of deletions for the old use-cases that only updated V1 Preferences 🧹
@@ -67,6 +66,7 @@ export class UpdatePreferences { | |||
return await this.findPreference(command, subscriber); | |||
} | |||
|
|||
@Instrument() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding some more instrumentation to the update preference flow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a follow-up PR (to keep this diff clean), I will rename this usecase from UpdatePreferences
to UpsertSubscriberPreferences
as it functions as such now.
} else { | ||
await this.updateUserPreference(command, subscriber); | ||
} | ||
await this.updateSubscriberPreference(command, subscriber); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As said above, we treat this as an upsert now. GetSubscriberPreferences
always returns a valid preference set now (falling back to default when nothing has been persisted), so there's no need to perform an extra lookup now before persisting the data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much cleaner!
…criber-api-inbox-api
…criber-api-inbox-api
…criber-api-inbox-api
…criber-api-inbox-api
} else { | ||
await this.updateUserPreference(command, subscriber); | ||
} | ||
await this.updateSubscriberPreference(command, subscriber); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much cleaner!
}); | ||
): Promise<Omit<UpdateSubscriberPreferenceResponseDto, 'template'>> { | ||
const channels = body.preferences?.reduce((acc, curr) => { | ||
acc[curr.type] = curr.enabled; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this enabled flag the same as the one we talked about in skipped tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is the channel-level flag. There are 2 enabled
flags:
enabled
at top level of V1 Preferences, which controls whether to use the subscriber preference during preference mergingenabled
flag for each channel, which controls delivery for the channel
What changed? Why was the change needed?
UpdatePreference
use-case for all Subscriber Preference updatesenabled
flagenabled
flag was introduced at a time beforecritical
workflows were available. Setting theenabled
flag to false on a preference set previously had the effect of preventing that Subscriber's preference settings from being read during notification delivery preference resolution. The Workflowcritical
flag handles this use-case in a more read-optimal way by requiring only a single Workflow resource to be mutated, rather than all Subscriber resources. I have left these tests in the codebase for now, we can debate further on complete deletion of theenabled
flag as part ofNV-4597
UpdatePreference
use-caseScreenshots
Expand for optional sections
Related enterprise PR
Special notes for your reviewer