Check new weekly email notification preferences
This commit is contained in:
parent
c6a60a6678
commit
5ab86c8362
|
@ -2,20 +2,14 @@ import * as functions from 'firebase-functions'
|
|||
import * as admin from 'firebase-admin'
|
||||
import { getAllPrivateUsers } from './utils'
|
||||
|
||||
export const resetWeeklyEmailsFlag = functions
|
||||
.runWith({ secrets: ['MAILGUN_KEY'] })
|
||||
// every Monday at 12 am PT (UTC -07:00) ( 12 hours before the emails will be sent)
|
||||
.pubsub.schedule('0 7 * * 1')
|
||||
export const resetWeeklyEmailsFlag = functions.pubsub // every Monday at 12 am PT (UTC -07:00) ( 12 hours before the emails will be sent)
|
||||
.schedule('0 7 * * 1')
|
||||
.timeZone('Etc/UTC')
|
||||
.onRun(async () => {
|
||||
const privateUsers = await getAllPrivateUsers()
|
||||
// get all users that haven't unsubscribed from weekly emails
|
||||
const privateUsersToSendEmailsTo = privateUsers.filter((user) => {
|
||||
return !user.unsubscribedFromWeeklyTrendingEmails
|
||||
})
|
||||
const firestore = admin.firestore()
|
||||
await Promise.all(
|
||||
privateUsersToSendEmailsTo.map(async (user) => {
|
||||
privateUsers.map(async (user) => {
|
||||
return firestore.collection('private-users').doc(user.id).update({
|
||||
weeklyTrendingEmailSent: false,
|
||||
})
|
||||
|
|
|
@ -48,7 +48,7 @@ async function sendTrendingMarketsEmailsToAllUsers() {
|
|||
// get all users that haven't unsubscribed from weekly emails
|
||||
const privateUsersToSendEmailsTo = privateUsers.filter((user) => {
|
||||
return (
|
||||
!user.unsubscribedFromWeeklyTrendingEmails &&
|
||||
user.notificationPreferences.trending_markets.includes('email') &&
|
||||
!user.weeklyTrendingEmailSent
|
||||
)
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue
Block a user