predikt/oracle/backend/scripts/add-new-notification-preference.ts
caelum0x 2b68bde5d5 Predikt: full Polymarket-style prediction market — web + mobile + on-chain + bots
Working tree is now the canonical repo. Off-chain play-money + trustless on-chain
(FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution,
mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-06 23:29:50 +03:00

63 lines
1.9 KiB
TypeScript

import * as admin from 'firebase-admin'
import { initAdmin } from 'shared/init-admin'
initAdmin()
import { getAllPrivateUsers, isProd } from 'shared/utils'
import {
getDefaultNotificationPreferences,
notification_preference,
} from 'common/user-notification-preferences'
import { filterDefined } from 'common/util/array'
import { chunk } from 'lodash'
const firestore = admin.firestore()
// Add your new pref here, and be sure to add the default as well
const NEW_PREFERENCE_KEY: notification_preference = 'new_match'
async function main() {
const privateUsers = filterDefined(await getAllPrivateUsers())
// const privateUsers = filterDefined([
// await getPrivateUser('AJwLWoo3xue32XIiAVrL5SyR1WB2'),
// ])
const defaults = getDefaultNotificationPreferences(!isProd())
let count = 0
const chunks = chunk(
privateUsers.filter(
(privateUser) =>
privateUser.notificationPreferences?.[NEW_PREFERENCE_KEY] === undefined
),
250
)
const total = chunks.length * 250
console.log('Updating', total, 'users')
for (const chunk of chunks) {
await Promise.all(
chunk.map(async (privateUser) => {
if (!privateUser.id) return
const currentUserPreferences = privateUser.notificationPreferences
? privateUser.notificationPreferences
: defaults
try {
await firestore
.collection('private-users')
.doc(privateUser.id)
.update({
notificationPreferences: {
...currentUserPreferences,
[NEW_PREFERENCE_KEY]: defaults[NEW_PREFERENCE_KEY],
},
})
} catch (e) {
console.log(e)
console.log('Error updating user', privateUser.id)
}
count++
if (count % 100 === 0) console.log('Updated', count, 'users of', total)
})
)
}
}
if (require.main === module) main().then(() => process.exit())