Avoid db call if possible

This commit is contained in:
Ian Philips 2022-05-17 16:10:32 -06:00
parent 66434fc9d6
commit 231bbb3517

View File

@ -34,7 +34,14 @@ export const onCreateComment = functions.firestore
let bet: Bet | undefined
let answer: Answer | undefined
if (comment.betId) {
if (comment.answerOutcome) {
answer =
contract.outcomeType === 'FREE_RESPONSE' && contract.answers
? contract.answers?.find(
(answer) => answer.id === comment.answerOutcome
)
: undefined
} else if (comment.betId) {
const betSnapshot = await firestore
.collection('contracts')
.doc(contractId)
@ -47,13 +54,6 @@ export const onCreateComment = functions.firestore
contract.outcomeType === 'FREE_RESPONSE' && contract.answers
? contract.answers.find((answer) => answer.id === bet?.outcome)
: undefined
} else if (comment.answerOutcome) {
answer =
contract.outcomeType === 'FREE_RESPONSE' && contract.answers
? contract.answers?.find(
(answer) => answer.id === comment.answerOutcome
)
: undefined
}
const comments = await getValues<Comment>(