Avoid db call if possible
This commit is contained in:
parent
66434fc9d6
commit
231bbb3517
|
@ -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>(
|
||||
|
|
Loading…
Reference in New Issue
Block a user