-
Notifications
You must be signed in to change notification settings - Fork 199
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
Save email preferences changes #4548
Conversation
Preview URL 🚀 : https://blurts-server-pr-4548-mgjlpikfea-uk.a.run.app |
Preview URL 🚀 : https://blurts-server-pr-4548-mgjlpikfea-uk.a.run.app |
function isEmailUpdateCommType( | ||
value: string, | ||
): value is EmailUpdateCommTypeOfOptions { | ||
return ["null", "affected", "primary"].includes(value); |
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.
Q: Should we create an enum
for these since we seem to semi-duplicate some values here and on L42+L45?
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.
Also, are there other possible values for value
that aren't one of these three?
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.
TypeScript enum
s are incompatible with the enum proposal for JS and changes runtime behaviour, and unions of literal strings (which we use here - EmailUpdateCommTypeOfOptions
) provide the same type safety, so it's recommended to use those.
That type also indicates that indeed, these are the only three valid values :)
That said... See my other comments.
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.
Sorry for another review with just remarks, but I hope these are small ones...
function isEmailUpdateCommType( | ||
value: string, | ||
): value is EmailUpdateCommTypeOfOptions { | ||
return ["null", "affected", "primary"].includes(value); |
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.
TypeScript enum
s are incompatible with the enum proposal for JS and changes runtime behaviour, and unions of literal strings (which we use here - EmailUpdateCommTypeOfOptions
) provide the same type safety, so it's recommended to use those.
That type also indicates that indeed, these are the only three valid values :)
That said... See my other comments.
@@ -48,8 +48,13 @@ export async function POST(req: NextRequest) { | |||
default: | |||
allEmailsToPrimary = null; | |||
} | |||
await setAllEmailsToPrimary(subscriber, allEmailsToPrimary); | |||
await setMonthlyMonitorReport(subscriber, monthlyMonitorReport); | |||
|
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.
I can't leave a comment on the relevant lines because they're unchanged, but it's best to update the type representing the request body to indicate that one of the properties should now be left empty:
export interface EmailUpdateCommOptionRequest {
instantBreachAlerts?: EmailUpdateCommTypeOfOptions;
monthlyMonitorReport?: boolean;
}
And then TS will show you what code to wrap in an if (typeof <x> !== "undefined")
, and you won't need the custom type guard (isEmailUpdateCommType
).
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.
fixed in 22b41c4
const body: EmailUpdateCommOptionRequest = { | ||
instantBreachAlerts: chosenOption, | ||
monthlyMonitorReport: monitorReportAllowed, | ||
}; |
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.
If you leave this in and make the change to the type that I suggested in the other file, then if people modify the backend, TS will warn us that we'll have to update the frontend as well.
(In fact, we probably want to do the same for the call to update monthlyMonitorReport
, since we have no checks that we're matching the request body type there either.)
const body: EmailUpdateCommOptionRequest = { | |
instantBreachAlerts: chosenOption, | |
monthlyMonitorReport: monitorReportAllowed, | |
}; | |
const body: EmailUpdateCommOptionRequest = { | |
instantBreachAlerts: chosenOption, | |
}; |
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.
fixed in 22b41c4
Preview URL 🚀 : https://blurts-server-pr-4548-mgjlpikfea-uk.a.run.app |
if (typeof instantBreachAlerts !== "undefined") { | ||
await setAllEmailsToPrimary(subscriber, allEmailsToPrimary); | ||
} | ||
if (typeof monthlyMonitorReport === "boolean") { |
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.
@Vinnl Can the condition here be !== undefined
too?
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.
Yep!
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.
It ended up just being an issue of passing the wrong var! my bad
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.
Works well for me! (But if it doesn't for you, let's investigate together.)
if (typeof instantBreachAlerts !== "undefined") { | ||
await setAllEmailsToPrimary(subscriber, allEmailsToPrimary); | ||
} | ||
if (typeof monthlyMonitorReport === "boolean") { |
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.
Yep!
Cleanup completed - database 'blurts-server-pr-4548' destroyed, cloud run service 'blurts-server-pr-4548' destroyed |
References:
Jira: MNTOR-3168
Description
Screenshot (if applicable)
Not applicable.
How to test
Checklist (Definition of Done)