update prefs safely
This commit is contained in:
parent
8d06e4b4d2
commit
a310963952
|
@ -1,16 +1,22 @@
|
|||
import * as admin from 'firebase-admin'
|
||||
|
||||
import { initAdmin } from './script-init'
|
||||
import { getAllPrivateUsers } from 'functions/src/utils'
|
||||
import { filterDefined } from 'common/lib/util/array'
|
||||
import { getPrivateUser } from '../utils'
|
||||
initAdmin()
|
||||
|
||||
const firestore = admin.firestore()
|
||||
|
||||
async function main() {
|
||||
const privateUsers = await getAllPrivateUsers()
|
||||
// const privateUsers = await getAllPrivateUsers()
|
||||
const privateUsers = filterDefined([
|
||||
await getPrivateUser('ddSo9ALC15N9FAZdKdA2qE3iIvH3'),
|
||||
])
|
||||
await Promise.all(
|
||||
privateUsers.map((privateUser) => {
|
||||
if (!privateUser.id) return Promise.resolve()
|
||||
if (privateUser.notificationPreferences.opt_out_all === undefined) {
|
||||
console.log('updating opt out all', privateUser.id)
|
||||
return firestore
|
||||
.collection('private-users')
|
||||
.doc(privateUser.id)
|
||||
|
@ -20,6 +26,8 @@ async function main() {
|
|||
opt_out_all: [],
|
||||
},
|
||||
})
|
||||
}
|
||||
return
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user