11import * as functions from "firebase-functions"
22import * as handlebars from "handlebars"
33import * as fs from "fs"
4- import { auth , db , Timestamp } from "../firebase"
4+ import { db , Timestamp } from "../firebase"
5+ //import { auth, db, Timestamp } from "../firebase" // Temporarily using email from the profile to test the non-auth issues
56import { getNextDigestAt , getNotificationStartDate } from "./helpers"
67import { startOfDay } from "date-fns"
78import { TestimonySubmissionNotificationFields , Profile } from "./types"
@@ -21,14 +22,15 @@ const EMAIL_TEMPLATE_PATH = "../email/digestEmail.handlebars"
2122
2223const path = require ( "path" )
2324
24- const getVerifiedUserEmail = async ( uid : string ) => {
25- const userRecord = await auth . getUser ( uid )
26- if ( userRecord && userRecord . email && userRecord . emailVerified ) {
27- return userRecord . email
28- } else {
29- return null
30- }
31- }
25+ // Temporarily using email from the profile to test the non-auth issues
26+ // const getVerifiedUserEmail = async (uid: string) => {
27+ // const userRecord = await auth.getUser(uid)
28+ // if (userRecord && userRecord.email && userRecord.emailVerified) {
29+ // return userRecord.email
30+ // } else {
31+ // return null
32+ // }
33+ // }
3234
3335// TODO: Batching (at both user + email level)?
3436// Going to wait until we have a better idea of the performance impact
@@ -44,6 +46,12 @@ const deliverEmailNotifications = async () => {
4446 . where ( "nextDigestAt" , "<=" , now )
4547 . get ( )
4648
49+ console . log (
50+ `Processing ${
51+ profilesSnapshot . size
52+ } profiles with nextDigestAt <= ${ now . toDate ( ) } `
53+ )
54+
4755 const emailPromises = profilesSnapshot . docs . map ( async profileDoc => {
4856 const profile = profileDoc . data ( ) as Profile
4957 if ( ! profile || ! profile . notificationFrequency ) {
@@ -53,7 +61,8 @@ const deliverEmailNotifications = async () => {
5361 return
5462 }
5563
56- const verifiedEmail = await getVerifiedUserEmail ( profileDoc . id )
64+ // Temporarily using email from the profile to test the non-auth issues
65+ const verifiedEmail = profile . email //await getVerifiedUserEmail(profileDoc.id)
5766 if ( ! verifiedEmail ) {
5867 console . log (
5968 `Skipping user ${ profileDoc . id } because they have no verified email address`
@@ -223,6 +232,7 @@ const renderToHtmlString = (digestData: NotificationEmailDigest) => {
223232// Firebase Functions
224233export const deliverNotifications = functions . pubsub
225234 . schedule ( "47 9 1 * 2" ) // 9:47 AM on the first day of the month and on Tuesdays
235+ . timeZone ( "America/New_York" )
226236 . onRun ( deliverEmailNotifications )
227237
228238export const httpsDeliverNotifications = functions . https . onRequest (
0 commit comments