manifold/functions/src/scripts/update-notification-preferences.ts

26 lines
825 B
TypeScript
Raw Normal View History

2022-09-14 16:26:08 +00:00
import * as admin from 'firebase-admin'
import { initAdmin } from './script-init'
2022-09-14 16:29:48 +00:00
import { getAllPrivateUsers } from 'functions/src/utils'
2022-09-14 16:26:08 +00:00
import { FieldValue } from 'firebase-admin/firestore'
initAdmin()
const firestore = admin.firestore()
async function main() {
2022-09-14 16:29:48 +00:00
const privateUsers = await getAllPrivateUsers()
2022-09-14 16:26:08 +00:00
await Promise.all(
privateUsers.map((privateUser) => {
if (!privateUser.id) return Promise.resolve()
return firestore.collection('private-users').doc(privateUser.id).update({
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
notificationPreferences: privateUser.notificationSubscriptionTypes,
notificationSubscriptionTypes: FieldValue.delete(),
})
})
)
}
if (require.main === module) main().then(() => process.exit())