manifold/functions/src/scripts/add-new-notification-preference.ts

31 lines
832 B
TypeScript
Raw Normal View History

import * as admin from 'firebase-admin'
import { initAdmin } from './script-init'
2022-10-10 14:21:37 +00:00
import { getAllPrivateUsers } from 'functions/src/utils'
initAdmin()
const firestore = admin.firestore()
async function main() {
2022-10-10 14:21:37 +00:00
const privateUsers = await getAllPrivateUsers()
await Promise.all(
privateUsers.map((privateUser) => {
if (!privateUser.id) return Promise.resolve()
2022-10-10 14:21:37 +00:00
if (privateUser.notificationPreferences.badges_awarded === undefined) {
2022-10-10 13:01:44 +00:00
return firestore
.collection('private-users')
.doc(privateUser.id)
.update({
notificationPreferences: {
...privateUser.notificationPreferences,
2022-10-10 14:21:37 +00:00
badges_awarded: ['browser'],
2022-10-10 13:01:44 +00:00
},
})
}
return
})
)
}
if (require.main === module) main().then(() => process.exit())