manifold/functions/src/scripts/create-private-users.ts
Marshall Polaris acc9c84e2e
More absolute imports (#156)
* Configure functions module to allow absolute imports

* Convert common imports in functions to be absolute

* Convert common imports in web to be absolute

* Convert lib imports in web to be absolute

* Convert hooks imports in web to be absolute

* Convert components imports in web to be absolute
2022-05-09 09:04:36 -04:00

49 lines
1.1 KiB
TypeScript

import * as admin from 'firebase-admin'
import * as _ from 'lodash'
import { initAdmin } from './script-init'
initAdmin()
import { PrivateUser, STARTING_BALANCE, User } from 'common/user'
const firestore = admin.firestore()
async function main() {
const snap = await firestore.collection('users').get()
const users = snap.docs.map((d) => d.data() as User)
for (let user of users) {
const fbUser = await admin.auth().getUser(user.id)
const email = fbUser.email
const { username } = user
const privateUser: PrivateUser = {
id: user.id,
email,
username,
}
if (user.totalDeposits === undefined) {
await firestore
.collection('users')
.doc(user.id)
.update({ totalDeposits: STARTING_BALANCE })
console.log('set starting balance for:', user.username)
}
try {
await firestore
.collection('private-users')
.doc(user.id)
.create(privateUser)
console.log('created private user for:', user.username)
} catch (_) {
// private user already created
}
}
}
if (require.main === module) main().then(() => process.exit())