manifold/functions/src/scripts/rename-user-contracts.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

40 lines
1.0 KiB
TypeScript

import * as admin from 'firebase-admin'
import { initAdmin } from './script-init'
initAdmin()
import { Contract } from '../../../common/contract'
import { getValues } from '../utils'
const firestore = admin.firestore()
async function renameUserContracts(
username: string,
newNames: { name: string; username: string }
) {
console.log(`Renaming contracts of ${username} to`, newNames)
const contracts = await getValues<Contract>(
firestore.collection('contracts').where('creatorUsername', '==', username)
)
console.log('Loaded', contracts.length, 'contracts by', username)
for (const contract of contracts) {
const contractRef = firestore.doc(`contracts/${contract.id}`)
console.log('Renaming', contract.slug)
await contractRef.update({
creatorUsername: newNames.username,
creatorName: newNames.name,
} as Partial<Contract>)
}
}
if (require.main === module)
renameUserContracts('ManticMarkets', {
username: 'ManifoldMarkets',
name: 'Manifold Markets',
}).then(() => process.exit())