From 4dcc9965030bc87103df7e6babfefba66fd3444b Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Tue, 17 May 2022 16:16:39 -0600 Subject: [PATCH] Include general comments note in comment emails --- functions/src/emails.ts | 8 ++++---- functions/src/on-create-comment.ts | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/functions/src/emails.ts b/functions/src/emails.ts index 84a5e3cb..f8549864 100644 --- a/functions/src/emails.ts +++ b/functions/src/emails.ts @@ -244,7 +244,8 @@ export const sendNewCommentEmail = async ( contract: Contract, comment: Comment, bet?: Bet, - answer?: Answer + answerText?: string, + answerId?: string ) => { const privateUser = await getPrivateUser(userId) if ( @@ -274,15 +275,14 @@ export const sendNewCommentEmail = async ( const from = `${commentorName} ` if (contract.outcomeType === 'FREE_RESPONSE') { - const answerText = answer?.text ?? '' - const answerNumber = `#${answer?.id ?? ''}` + const answerNumber = answerId ? `#${answerId}` : '' await sendTemplateEmail( privateUser.email, subject, 'market-answer-comment', { - answer: answerText, + answer: answerText ?? '', answerNumber, commentorName, commentorAvatarUrl: commentorAvatarUrl ?? '', diff --git a/functions/src/on-create-comment.ts b/functions/src/on-create-comment.ts index 77c5141f..b48676d0 100644 --- a/functions/src/on-create-comment.ts +++ b/functions/src/on-create-comment.ts @@ -33,14 +33,17 @@ export const onCreateComment = functions.firestore .update({ lastCommentTime, lastUpdatedTime: Date.now() }) let bet: Bet | undefined - let answer: Answer | undefined + let answerText: string | undefined + let answerId: string | undefined if (comment.answerOutcome) { - answer = + const answer = contract.outcomeType === 'FREE_RESPONSE' && contract.answers ? contract.answers?.find( (answer) => answer.id === comment.answerOutcome ) : undefined + answerText = answer?.text + answerId = answer?.id } else if (comment.betId) { const betSnapshot = await firestore .collection('contracts') @@ -50,10 +53,14 @@ export const onCreateComment = functions.firestore .get() bet = betSnapshot.data() as Bet - answer = + const answer = contract.outcomeType === 'FREE_RESPONSE' && contract.answers ? contract.answers.find((answer) => answer.id === bet?.outcome) : undefined + answerText = answer?.text + answerId = answer?.id + } else if (contract.outcomeType === 'FREE_RESPONSE') { + answerText = 'General Comments' } const comments = await getValues( @@ -73,7 +80,8 @@ export const onCreateComment = functions.firestore contract, comment, bet, - answer + answerText, + answerId ) ) )