diff --git a/server/src/controllers/Events/resolver.ts b/server/src/controllers/Events/resolver.ts index fa97f2b528..b09e3cc2a0 100644 --- a/server/src/controllers/Events/resolver.ts +++ b/server/src/controllers/Events/resolver.ts @@ -39,10 +39,6 @@ import { deleteEventReminders, updateRemindAt, } from '../../services/Reminders'; -import { - generateToken, - UnsubscribeType, -} from '../../services/UnsubscribeToken'; import { cancelCalendarEvent, deleteCalendarEvent, @@ -58,6 +54,10 @@ import { } from '../../util/calendar'; import { updateWaitlistForUserRemoval } from '../../util/waitlist'; import { redactSecrets } from '../../util/redact-secrets'; +import { + getChapterUnsubscribeOptions, + getEventUnsubscribeOptions, +} from '../../util/eventEmail'; import { EventInputs } from './inputs'; const eventUserIncludes = { @@ -86,31 +86,6 @@ const isPhysical = (venue_type: events_venue_type_enum) => const isOnline = (venue_type: events_venue_type_enum) => venue_type !== events_venue_type_enum.Physical; -const getUnsubscribeOptions = ({ - chapterId, - eventId, - userId, -}: { - chapterId: number; - eventId: number; - userId: number; -}) => { - const chapterUnsubscribeToken = generateToken( - UnsubscribeType.Chapter, - chapterId, - userId, - ); - const eventUnsubscribeToken = generateToken( - UnsubscribeType.Event, - eventId, - userId, - ); - return ` -Unsubscribe Options
-- Attend this event, but only turn off future notifications for this event
-- Or, stop receiving notifications about new events by unfollowing chapter`; -}; - const sendRsvpInvitation = async ( user: Required['user'], event: events & { venue: venues | null }, @@ -123,7 +98,7 @@ const sendRsvpInvitation = async ( }; if (event.venue?.name) linkDetails.location = event.venue?.name; - const unsubscribeOptions = getUnsubscribeOptions({ + const unsubscribeOptions = getEventUnsubscribeOptions({ chapterId: event.chapter_id, eventId: event.id, userId: user.id, @@ -247,11 +222,10 @@ const rsvpNotifyAdministrators = async ( await batchSender(function* () { for (const { chapter_id, user } of chapterAdministrators) { const email = user.email; - const chapterUnsubscribeToken = generateToken( - UnsubscribeType.Chapter, - chapter_id, - user.id, - ); + const chapterUnsubscribeToken = getChapterUnsubscribeOptions({ + chapterId: chapter_id, + userId: user.id, + }); const text = `${body}
${linkToEvent}.
+ - To stop receiving notifications about new events in this chapter, go to ${linkToChapter}.
`; +}; + +export const getChapterUnsubscribeOptions = ({ + chapterId, + userId, +}: { + chapterId: number; + userId: number; +}) => { + generateToken(UnsubscribeType.Chapter, chapterId, userId); +};