2022-01-07 00:05:48 +00:00
|
|
|
import * as admin from 'firebase-admin'
|
2022-01-10 21:07:57 +00:00
|
|
|
|
2022-01-30 21:11:01 +00:00
|
|
|
import { initAdmin } from './script-init'
|
2022-04-20 04:31:46 +00:00
|
|
|
initAdmin()
|
2022-01-30 21:11:01 +00:00
|
|
|
|
2022-05-15 17:39:42 +00:00
|
|
|
import { Contract } from '../../../common/contract'
|
2022-01-07 00:05:48 +00:00
|
|
|
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())
|