Send emails for comments without bets
This commit is contained in:
		
							parent
							
								
									8291a05f32
								
							
						
					
					
						commit
						5861817e5a
					
				|  | @ -167,7 +167,7 @@ export const sendNewCommentEmail = async ( | ||||||
|   commentCreator: User, |   commentCreator: User, | ||||||
|   contract: Contract, |   contract: Contract, | ||||||
|   comment: Comment, |   comment: Comment, | ||||||
|   bet: Bet, |   bet?: Bet, | ||||||
|   answer?: Answer |   answer?: Answer | ||||||
| ) => { | ) => { | ||||||
|   const privateUser = await getPrivateUser(userId) |   const privateUser = await getPrivateUser(userId) | ||||||
|  | @ -186,8 +186,11 @@ export const sendNewCommentEmail = async ( | ||||||
|   const { name: commentorName, avatarUrl: commentorAvatarUrl } = commentCreator |   const { name: commentorName, avatarUrl: commentorAvatarUrl } = commentCreator | ||||||
|   const { text } = comment |   const { text } = comment | ||||||
| 
 | 
 | ||||||
|   const { amount, sale, outcome } = bet |   let betDescription = '' | ||||||
|   let betDescription = `${sale ? 'sold' : 'bought'} M$ ${Math.round(amount)}` |   if (bet) { | ||||||
|  |     const { amount, sale } = bet | ||||||
|  |     betDescription = `${sale ? 'sold' : 'bought'} M$ ${Math.round(amount)}` | ||||||
|  |   } | ||||||
| 
 | 
 | ||||||
|   const subject = `Comment on ${question}` |   const subject = `Comment on ${question}` | ||||||
|   const from = `${commentorName} <info@manifold.markets>` |   const from = `${commentorName} <info@manifold.markets>` | ||||||
|  | @ -208,16 +211,17 @@ export const sendNewCommentEmail = async ( | ||||||
|         comment: text, |         comment: text, | ||||||
|         marketUrl, |         marketUrl, | ||||||
|         unsubscribeUrl, |         unsubscribeUrl, | ||||||
|         betDescription, |         betDescription: betDescription, | ||||||
|       }, |       }, | ||||||
|       { from } |       { from } | ||||||
|     ) |     ) | ||||||
|   } else { |   } else { | ||||||
|  |     if (bet) { | ||||||
|       betDescription = `${betDescription} of ${toDisplayResolution( |       betDescription = `${betDescription} of ${toDisplayResolution( | ||||||
|         contract, |         contract, | ||||||
|       outcome |         bet.outcome | ||||||
|       )}` |       )}` | ||||||
| 
 |     } | ||||||
|     await sendTemplateEmail( |     await sendTemplateEmail( | ||||||
|       privateUser.email, |       privateUser.email, | ||||||
|       subject, |       subject, | ||||||
|  |  | ||||||
|  | @ -6,6 +6,7 @@ import { getContract, getUser, getValues } from './utils' | ||||||
| import { Comment } from '../../common/comment' | import { Comment } from '../../common/comment' | ||||||
| import { sendNewCommentEmail } from './emails' | import { sendNewCommentEmail } from './emails' | ||||||
| import { Bet } from '../../common/bet' | import { Bet } from '../../common/bet' | ||||||
|  | import { Answer } from '../../common/answer' | ||||||
| 
 | 
 | ||||||
| const firestore = admin.firestore() | const firestore = admin.firestore() | ||||||
| 
 | 
 | ||||||
|  | @ -24,18 +25,22 @@ export const onCreateComment = functions.firestore | ||||||
|     const commentCreator = await getUser(comment.userId) |     const commentCreator = await getUser(comment.userId) | ||||||
|     if (!commentCreator) return |     if (!commentCreator) return | ||||||
| 
 | 
 | ||||||
|  |     let bet: Bet | undefined | ||||||
|  |     let answer: Answer | undefined | ||||||
|  |     if (comment.betId) { | ||||||
|       const betSnapshot = await firestore |       const betSnapshot = await firestore | ||||||
|         .collection('contracts') |         .collection('contracts') | ||||||
|         .doc(contractId) |         .doc(contractId) | ||||||
|         .collection('bets') |         .collection('bets') | ||||||
|         .doc(comment.betId) |         .doc(comment.betId) | ||||||
|         .get() |         .get() | ||||||
|     const bet = betSnapshot.data() as Bet |       bet = betSnapshot.data() as Bet | ||||||
| 
 | 
 | ||||||
|     const answer = |       answer = | ||||||
|         contract.outcomeType === 'FREE_RESPONSE' && contract.answers |         contract.outcomeType === 'FREE_RESPONSE' && contract.answers | ||||||
|         ? contract.answers.find((answer) => answer.id === bet.outcome) |           ? contract.answers.find((answer) => answer.id === bet?.outcome) | ||||||
|           : undefined |           : undefined | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     const comments = await getValues<Comment>( |     const comments = await getValues<Comment>( | ||||||
|       firestore.collection('contracts').doc(contractId).collection('comments') |       firestore.collection('contracts').doc(contractId).collection('comments') | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user