1
1
import * as functions from "firebase-functions"
2
2
import * as handlebars from "handlebars"
3
3
import * 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
5
6
import { getNextDigestAt , getNotificationStartDate } from "./helpers"
6
7
import { startOfDay } from "date-fns"
7
8
import { TestimonySubmissionNotificationFields , Profile } from "./types"
@@ -21,14 +22,15 @@ const EMAIL_TEMPLATE_PATH = "../email/digestEmail.handlebars"
21
22
22
23
const path = require ( "path" )
23
24
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
+ // }
32
34
33
35
// TODO: Batching (at both user + email level)?
34
36
// Going to wait until we have a better idea of the performance impact
@@ -44,6 +46,12 @@ const deliverEmailNotifications = async () => {
44
46
. where ( "nextDigestAt" , "<=" , now )
45
47
. get ( )
46
48
49
+ console . log (
50
+ `Processing ${
51
+ profilesSnapshot . size
52
+ } profiles with nextDigestAt <= ${ now . toDate ( ) } `
53
+ )
54
+
47
55
const emailPromises = profilesSnapshot . docs . map ( async profileDoc => {
48
56
const profile = profileDoc . data ( ) as Profile
49
57
if ( ! profile || ! profile . notificationFrequency ) {
@@ -53,7 +61,8 @@ const deliverEmailNotifications = async () => {
53
61
return
54
62
}
55
63
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)
57
66
if ( ! verifiedEmail ) {
58
67
console . log (
59
68
`Skipping user ${ profileDoc . id } because they have no verified email address`
@@ -223,6 +232,7 @@ const renderToHtmlString = (digestData: NotificationEmailDigest) => {
223
232
// Firebase Functions
224
233
export const deliverNotifications = functions . pubsub
225
234
. schedule ( "47 9 1 * 2" ) // 9:47 AM on the first day of the month and on Tuesdays
235
+ . timeZone ( "America/New_York" )
226
236
. onRun ( deliverEmailNotifications )
227
237
228
238
export const httpsDeliverNotifications = functions . https . onRequest (
0 commit comments