manifold/functions/src/scripts/remove-answer-ante.ts
Marshall Polaris 47f10301c8
Change lodash stuff so that it can be tree-shaken out of build (#233)
* Set common package.json sideEffects: false

* Configure SWC to modularize lodash imports

* Import specific lodash functions instead of _

* Add an eslint rule to avoid full lodash import
2022-05-22 01:36:05 -07:00

44 lines
1.1 KiB
TypeScript

import * as admin from 'firebase-admin'
import { initAdmin } from './script-init'
initAdmin()
import { Bet } from '../../../common/bet'
import { Contract } from '../../../common/contract'
import { getValues } from '../utils'
async function removeAnswerAnte() {
const firestore = admin.firestore()
console.log('Removing isAnte from bets on answers')
const contracts = await getValues<Contract>(
firestore
.collection('contracts')
.where('outcomeType', '==', 'FREE_RESPONSE')
)
console.log('Loaded', contracts, 'contracts')
for (const contract of contracts) {
const betsSnapshot = await firestore
.collection('contracts')
.doc(contract.id)
.collection('bets')
.get()
console.log('updating', contract.question)
for (const doc of betsSnapshot.docs) {
const bet = doc.data() as Bet
if (bet.isAnte && bet.outcome !== '0') {
console.log('updating', bet.outcome)
await doc.ref.update('isAnte', false)
}
}
}
}
if (require.main === module) {
removeAnswerAnte().then(() => process.exit())
}