Don't unnecessarily query contract in onCreateBet (#528)
This commit is contained in:
parent
0820cc8f4d
commit
61a2bcb609
|
@ -1,7 +1,6 @@
|
||||||
import * as functions from 'firebase-functions'
|
import * as functions from 'firebase-functions'
|
||||||
import * as admin from 'firebase-admin'
|
import * as admin from 'firebase-admin'
|
||||||
|
|
||||||
import { getContract } from './utils'
|
|
||||||
import { Bet } from '../../common/bet'
|
import { Bet } from '../../common/bet'
|
||||||
|
|
||||||
const firestore = admin.firestore()
|
const firestore = admin.firestore()
|
||||||
|
@ -12,16 +11,11 @@ export const onCreateBet = functions.firestore
|
||||||
const { contractId } = context.params as {
|
const { contractId } = context.params as {
|
||||||
contractId: string
|
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 bet = change.data() as Bet
|
||||||
const lastBetTime = bet.createdTime
|
const lastBetTime = bet.createdTime
|
||||||
|
|
||||||
await firestore
|
await firestore
|
||||||
.collection('contracts')
|
.collection('contracts')
|
||||||
.doc(contract.id)
|
.doc(contractId)
|
||||||
.update({ lastBetTime, lastUpdatedTime: Date.now() })
|
.update({ lastBetTime, lastUpdatedTime: Date.now() })
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user