diff --git a/backend/email/emails/functions/create-emails.ts b/backend/email/emails/functions/create-emails.ts index 4e1a27db..dbf424fd 100644 --- a/backend/email/emails/functions/create-emails.ts +++ b/backend/email/emails/functions/create-emails.ts @@ -1,12 +1,12 @@ import {PrivateUser, User} from 'common/user' import {sleep} from 'common/util/time' -import {sendOutreachEmail} from 'email/functions/helpers' +import {sendShareCompassEmail} from 'email/functions/helpers' import {keyBy} from 'lodash' import {getAllPrivateUsers, getAllUsers, getUser} from 'shared/utils' export const createEmails = async ( sendEmail: (toUser: User, privateUser: PrivateUser) => Promise, - ids: string[], + {ids, startIndex, n}: {ids: string[]; startIndex: number; n: number}, ) => { let users = [] if (ids.length) { @@ -17,6 +17,15 @@ export const createEmails = async ( } else { users = await getAllUsers() } + + if (startIndex) { + users = users.slice(startIndex) + } + + if (n) { + users = users.slice(0, n) + } + const _privateUsers = await getAllPrivateUsers() const privateUsers = keyBy(_privateUsers, 'id') @@ -38,6 +47,6 @@ export const createEmails = async ( } } -export const createShareEmails = async ({ids}: {ids: string[]}) => { - return await createEmails(sendOutreachEmail, ids) +export const createShareCompassEmails = async (options: any) => { + return await createEmails(sendShareCompassEmail, options) } diff --git a/backend/email/emails/functions/helpers.tsx b/backend/email/emails/functions/helpers.tsx index 3fadeaa6..d2475e9a 100644 --- a/backend/email/emails/functions/helpers.tsx +++ b/backend/email/emails/functions/helpers.tsx @@ -1,4 +1,5 @@ import {render} from '@react-email/render' +import {defaultLocale} from 'common/constants' import {debug} from 'common/logger' import {MatchesType} from 'common/profiles/bookmarked_searches' import {PrivateUser, User} from 'common/user' @@ -195,7 +196,7 @@ export const sendNewEndorsementEmail = async ( }) } -export const sendOutreachEmail = async (toUser: User, privateUser: PrivateUser) => { +export const sendShareCompassEmail = async (toUser: User, privateUser: PrivateUser) => { const {sendToEmail, unsubscribeUrl} = getNotificationDestinationsForUser( privateUser, 'platform_updates', @@ -208,7 +209,7 @@ export const sendOutreachEmail = async (toUser: User, privateUser: PrivateUser) const locale = privateUser?.locale const t = createT(locale) - console.log(`Sending email to ${privateUser.email} in ${locale}`) + console.log(`Sending email to ${privateUser.email} in ${locale ?? defaultLocale} (${toUser.id})`) const subject = t( 'email.share.preview',