Skip to content

Commit

Permalink
fix: remove dup primary_email from new table
Browse files Browse the repository at this point in the history
  • Loading branch information
mansaj committed Aug 30, 2024
1 parent 77ab60c commit 9469811
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/app/api/utils/email.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ export async function generateUnsubscribeLinkForSubscriber(
const sub = await addEmailPreferenceForSubscriber(
subscriber.id,
{
primary_email: subscriber.primary_email,
unsubscribe_token: unsubToken,
},
["primary_email", "unsubscribe_token"],
["unsubscribe_token"],
);
return `${process.env.SERVER_URL}/api/v1/user/unsubscribe-email?email=${sub.primary_email}&token=${sub.unsubscribe_token}`;
return `${process.env.SERVER_URL}/api/v1/user/unsubscribe-email?email=${subscriber.primary_email}&token=${sub.unsubscribe_token}`;
} catch (e) {
console.error("generate_unsubscribe_link", {
exception: e as string,
Expand Down
3 changes: 0 additions & 3 deletions src/db/tables/subscriber_email_preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const knex = createDbConnection();
// NOTE: The "subscriber_email_preferences" table only has attributes for free reports
// TODO: modify the CRUD utils after MNTOR-3557
interface SubscriberFreeEmailPreferencesInput {
primary_email?: string;
unsubscribe_token?: string;
monthly_monitor_report_free?: boolean;
monthly_monitor_report_free_at?: Date;
Expand Down Expand Up @@ -49,7 +48,6 @@ async function addEmailPreferenceForSubscriber(
res = await knex("subscriber_email_preferences")
.insert({
subscriber_id: subscriberId,
primary_email: preference.primary_email || "",
unsubscribe_token: preference.unsubscribe_token || "",
monthly_monitor_report_free:
preference.monthly_monitor_report_free ?? true,
Expand Down Expand Up @@ -224,7 +222,6 @@ async function unsubscribeMonthlyMonitorReportForEmail(email: string) {
);
} else if (sub.id && sub.monthly_monitor_report_free) {
await updateEmailPreferenceForSubscriber(sub.id, true, {
primary_email: sub.primary_email,
monthly_monitor_report_free: false,
});
} else {
Expand Down

0 comments on commit 9469811

Please sign in to comment.