Skip to content
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

MNTOR-3919: getting setter for churn email state (Part 2) #5480

Merged
merged 4 commits into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/db/tables/subscribers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,33 @@ async function markFirstDataBrokerRemovalFixedEmailAsJustSent(
}

/* c8 ignore stop */

// Not covered by tests; mostly side-effects. See test-coverage.md#mock-heavy
/* c8 ignore start */
async function markChurnPreventionEmailAsJustSent(
subscriberId: SubscriberRow["id"],
) {
const affectedSubscribers = await knex("subscribers")
.update({
// @ts-ignore knex.fn.now() results in it being set to a date,
// even if it's not typed as a JS date object:
churn_prevention_email_sent_at: knex.fn.now(),
// @ts-ignore knex.fn.now() results in it being set to a date,
// even if it's not typed as a JS date object:
updated_at: knex.fn.now(),
})
.where("id", subscriberId)
.returning("*");

if (affectedSubscribers.length !== 1) {
throw new Error(
`Attempted to mark 1 user as having just been sent the churn prevention email, but instead found [${affectedSubscribers.length}] matching its ID.`,
);
}
}

/* c8 ignore stop */

// Not covered by tests; mostly side-effects. See test-coverage.md#mock-heavy
/* c8 ignore start */
async function markMonthlyActivityPlusEmailAsJustSent(
Expand Down Expand Up @@ -669,6 +696,18 @@ async function isSubscriberPlus(subscriberId: SubscriberRow["id"]) {
}
/* c8 ignore stop */

// Not covered by tests; mostly side-effects. See test-coverage.md#mock-heavy
/* c8 ignore start */
async function getChurnPreventionEmailSentAt(
subscriberId: SubscriberRow["id"],
) {
const res = await knex("subscribers")
.select("churn_prevention_email_sent_at")
.where("id", subscriberId);
return res?.[0]?.["churn_prevention_email_sent_at"] ?? null;
}
/* c8 ignore stop */

export {
getOnerepProfileId,
getSubscribersByHashes,
Expand All @@ -685,6 +724,7 @@ export {
getPotentialSubscribersWaitingForFirstDataBrokerRemovalFixedEmail,
getFreeSubscribersWaitingForMonthlyEmail,
getPlusSubscribersWaitingForMonthlyEmail,
markChurnPreventionEmailAsJustSent,
markFirstDataBrokerRemovalFixedEmailAsJustSent,
markMonthlyActivityPlusEmailAsJustSent,
deleteUnverifiedSubscribers,
Expand All @@ -693,6 +733,7 @@ export {
deleteOnerepProfileId,
incrementSignInCountForEligibleFreeUser,
getSignInCount,
getChurnPreventionEmailSentAt,
unresolveAllBreaches,
isSubscriberPlus,
knex as knexSubscribers,
Expand Down
Loading