Skip to content

Commit c2d2f48

Browse files
committed
fix(notifications): Using shared firebase-admin for notification email function, updating log messages for readability
1 parent b6b14d3 commit c2d2f48

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

functions/src/notifications/deliverNotifications.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import * as functions from "firebase-functions"
2-
import * as admin from "firebase-admin"
32
import * as handlebars from "handlebars"
43
import * as fs from "fs"
5-
import { Timestamp } from "../firebase"
4+
import { auth, db, Timestamp } from "../firebase"
65
import { getNextDigestAt, getNotificationStartDate } from "./helpers"
76
import { startOfDay } from "date-fns"
87
import { TestimonySubmissionNotificationFields, Profile } from "./types"
@@ -13,17 +12,13 @@ import {
1312
UserDigest
1413
} from "./emailTypes"
1514
import { prepareHandlebars } from "../email/handlebarsHelpers"
16-
import { getAuth } from "firebase-admin/auth"
1715
import { Frequency } from "../auth/types"
1816

1917
const NUM_BILLS_TO_DISPLAY = 4
2018
const NUM_USERS_TO_DISPLAY = 4
2119
const NUM_TESTIMONIES_TO_DISPLAY = 6
2220
const EMAIL_TEMPLATE_PATH = "../email/digestEmail.handlebars"
2321

24-
// Get a reference to the Firestore database
25-
const db = admin.firestore()
26-
const auth = getAuth()
2722
const path = require("path")
2823

2924
const getVerifiedUserEmail = async (uid: string) => {
@@ -103,7 +98,9 @@ const deliverEmailNotifications = async () => {
10398
batch.update(profileDoc.ref, { nextDigestAt })
10499
await batch.commit()
105100

106-
console.log(`Updated nextDigestAt for ${profileDoc.id} to ${nextDigestAt}`)
101+
console.log(
102+
`Updated nextDigestAt for ${profileDoc.id} to ${nextDigestAt?.toDate()}`
103+
)
107104
})
108105

109106
// Wait for all email documents to be created

0 commit comments

Comments
 (0)