in src/cancel-reminders/lib/db.ts [40:85]
export async function cancelPendingSignups(
reminderCode: string,
pool: Pool,
): Promise<number> {
const now = new Date();
// Find the signup for the given reminder_code, then use the identity_id to cancel all reminders for that user
const identityId = await getIdentityIdForReminderCode(reminderCode, pool);
if (identityId !== null) {
const oneOffQuery: QueryConfig = {
text: `
UPDATE
one_off_reminder_signups
SET
reminder_cancelled_at = $1
WHERE
identity_id = $2
AND reminder_cancelled_at IS NULL
`,
values: [now.toISOString(), identityId],
};
const recurringQuery: QueryConfig = {
text: `
UPDATE
recurring_reminder_signups
SET
reminder_cancelled_at = $1
WHERE
identity_id = $2
AND reminder_cancelled_at IS NULL
`,
values: [now.toISOString(), identityId],
};
return Promise.all([
runWithLogging(oneOffQuery, pool),
runWithLogging(recurringQuery, pool),
]).then(
([oneOffResult, recurringResult]) =>
(oneOffResult.rowCount ?? 0) + (recurringResult.rowCount ?? 0),
);
}
return Promise.resolve(0);
}