manifold/functions/src/scripts/make-contracts-public.ts
Marshall Polaris 5dbe16ec8d
Change how Firebase scripts auth (#87)
Now the admin key path is loaded from enviroment variables instead
of being hardcoded in script-init.ts.
2022-04-19 23:31:46 -05:00

28 lines
788 B
TypeScript

import * as admin from 'firebase-admin'
import * as _ from 'lodash'
import { initAdmin } from './script-init'
initAdmin()
import { Contract } from '../../../common/contract'
const firestore = admin.firestore()
async function makeContractsPublic() {
console.log('Updating contracts to be public')
const snapshot = await firestore.collection('contracts').get()
const contracts = snapshot.docs.map((doc) => doc.data() as Contract)
console.log('Loaded', contracts.length, 'contracts')
for (const contract of contracts) {
const contractRef = firestore.doc(`contracts/${contract.id}`)
console.log('Updating', contract.question)
await contractRef.update({ visibility: 'public' })
}
}
if (require.main === module) makeContractsPublic().then(() => process.exit())