2022-05-01 16:36:54 +00:00
|
|
|
import * as functions from 'firebase-functions'
|
|
|
|
import * as admin from 'firebase-admin'
|
|
|
|
|
2022-05-15 17:39:42 +00:00
|
|
|
import { Bet } from '../../common/bet'
|
2022-05-01 16:36:54 +00:00
|
|
|
|
|
|
|
const firestore = admin.firestore()
|
|
|
|
|
|
|
|
export const onCreateBet = functions.firestore
|
|
|
|
.document('contracts/{contractId}/bets/{betId}')
|
|
|
|
.onCreate(async (change, context) => {
|
|
|
|
const { contractId } = context.params as {
|
|
|
|
contractId: string
|
|
|
|
}
|
|
|
|
const bet = change.data() as Bet
|
|
|
|
const lastBetTime = bet.createdTime
|
|
|
|
|
|
|
|
await firestore
|
|
|
|
.collection('contracts')
|
2022-06-17 07:15:37 +00:00
|
|
|
.doc(contractId)
|
2022-05-01 16:36:54 +00:00
|
|
|
.update({ lastBetTime, lastUpdatedTime: Date.now() })
|
|
|
|
})
|