2022-08-19 22:02:52 +00:00
|
|
|
import * as functions from 'firebase-functions'
|
|
|
|
import * as dayjs from 'dayjs'
|
|
|
|
import * as utc from 'dayjs/plugin/utc'
|
|
|
|
dayjs.extend(utc)
|
|
|
|
|
|
|
|
import { getPrivateUser } from './utils'
|
2022-09-20 16:14:55 +00:00
|
|
|
import { User } from '../../common/user'
|
2022-09-20 16:17:37 +00:00
|
|
|
import { sendPersonalFollowupEmail, sendWelcomeEmail } from './emails'
|
2022-08-19 22:02:52 +00:00
|
|
|
|
|
|
|
export const onCreateUser = functions
|
|
|
|
.runWith({ secrets: ['MAILGUN_KEY'] })
|
|
|
|
.firestore.document('users/{userId}')
|
|
|
|
.onCreate(async (snapshot) => {
|
|
|
|
const user = snapshot.data() as User
|
|
|
|
const privateUser = await getPrivateUser(user.id)
|
|
|
|
if (!privateUser) return
|
|
|
|
|
|
|
|
await sendWelcomeEmail(user, privateUser)
|
|
|
|
|
2022-08-20 19:04:55 +00:00
|
|
|
const followupSendTime = dayjs().add(48, 'hours').toString()
|
2022-08-19 22:02:52 +00:00
|
|
|
await sendPersonalFollowupEmail(user, privateUser, followupSendTime)
|
|
|
|
})
|