Skip to content

Commit 461a998

Browse files
committed
fix: resolving dependency issue with Profile type
1 parent 10c9b72 commit 461a998

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

functions/src/notifications/deliverNotifications.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as fs from "fs"
55
import { Timestamp } from "../firebase"
66
import { getNextDigestAt, getNotificationStartDate } from "./helpers"
77
import { startOfDay } from "date-fns"
8-
import { TestimonySubmissionNotificationFields } from "./types"
8+
import { TestimonySubmissionNotificationFields, Profile } from "./types"
99
import {
1010
BillDigest,
1111
NotificationEmailDigest,
@@ -15,7 +15,6 @@ import {
1515
import { prepareHandlebars } from "../email/handlebarsHelpers"
1616
import { getAuth } from "firebase-admin/auth"
1717
import { Frequency } from "../auth/types"
18-
import { Profile } from "../../../components/db/profile/types"
1918

2019
const NUM_BILLS_TO_DISPLAY = 4
2120
const NUM_USERS_TO_DISPLAY = 4
@@ -51,8 +50,8 @@ const deliverEmailNotifications = async () => {
5150
.get()
5251

5352
const emailPromises = profilesSnapshot.docs.map(async profileDoc => {
54-
const user = profileDoc.data() as Profile
55-
if (!user || !user.notificationFrequency) {
53+
const profile = profileDoc.data() as Profile
54+
if (!profile || !profile.notificationFrequency) {
5655
console.log(
5756
`User ${profileDoc.id} has no notificationFrequency - skipping`
5857
)
@@ -70,7 +69,7 @@ const deliverEmailNotifications = async () => {
7069
const digestData = await buildDigestData(
7170
profileDoc.id,
7271
now,
73-
user.notificationFrequency
72+
profile.notificationFrequency
7473
)
7574

7675
// If there are no new notifications, don't send an email
@@ -98,7 +97,7 @@ const deliverEmailNotifications = async () => {
9897
console.log(`Saved email message to user ${profileDoc.id}`)
9998
}
10099

101-
const nextDigestAt = getNextDigestAt(user.notificationFrequency)
100+
const nextDigestAt = getNextDigestAt(profile.notificationFrequency)
102101
await profileDoc.ref.update({ nextDigestAt })
103102

104103
console.log(`Updated nextDigestAt for ${profileDoc.id} to ${nextDigestAt}`)

functions/src/notifications/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Frequency } from "../auth/types"
12
import { BillHistory } from "../bills/types"
23
import { Timestamp } from "../firebase"
34

@@ -62,3 +63,8 @@ export interface BillHistoryUpdateNotificationFields {
6263
}
6364
createdAt: FirebaseFirestore.Timestamp
6465
}
66+
67+
export interface Profile {
68+
notificationFrequency?: Frequency
69+
nextDigestAt?: FirebaseFirestore.Timestamp
70+
}

0 commit comments

Comments
 (0)