Don't unnecessarily query contract in onCreateBet (#528)

This commit is contained in:
Marshall Polaris 2022-06-17 00:15:37 -07:00 committed by GitHub
parent 0820cc8f4d
commit 61a2bcb609
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,6 @@
import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'
import { getContract } from './utils'
import { Bet } from '../../common/bet'
const firestore = admin.firestore()
@ -12,16 +11,11 @@ export const onCreateBet = functions.firestore
const { contractId } = context.params as {
contractId: string
}
const contract = await getContract(contractId)
if (!contract)
throw new Error('Could not find contract corresponding with bet')
const bet = change.data() as Bet
const lastBetTime = bet.createdTime
await firestore
.collection('contracts')
.doc(contract.id)
.doc(contractId)
.update({ lastBetTime, lastUpdatedTime: Date.now() })
})