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>
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
// Fill all groups without privacyStatus to 'public'
|
|
|
|
import * as admin from 'firebase-admin'
|
|
import { initAdmin } from 'shared/init-admin'
|
|
import { log, writeAsync } from 'shared/utils'
|
|
|
|
initAdmin()
|
|
const db = admin.firestore()
|
|
|
|
if (require.main === module) {
|
|
async function updatePostsWithGroupIdAndVisibility(): Promise<void> {
|
|
try {
|
|
// Get all groups with 'postIds' field
|
|
const groupSnapshot = await db
|
|
.collection('groups')
|
|
.where('postIds', '!=', null)
|
|
.get()
|
|
|
|
if (groupSnapshot.empty) {
|
|
console.log('No groups with postIds found.')
|
|
return
|
|
}
|
|
|
|
const updatePostPromises: Promise<any>[] = []
|
|
|
|
// Iterate over groups and find corresponding posts
|
|
groupSnapshot.forEach((groupDoc) => {
|
|
const groupData = groupDoc.data()
|
|
const groupId = groupDoc.id
|
|
const postIds = groupData.postIds
|
|
const visibility = groupData.privacyStatus
|
|
|
|
// Iterate over postIds and update corresponding posts
|
|
postIds.forEach((postId: string) => {
|
|
const postRef = db.collection('posts').doc(postId)
|
|
|
|
// Check if the post exists before updating
|
|
updatePostPromises.push(
|
|
postRef.get().then((postDoc) => {
|
|
if (postDoc.exists) {
|
|
return postRef.update({ groupId, visibility })
|
|
} else {
|
|
console.warn(
|
|
`Post document with ID '${postId}' does not exist.`
|
|
)
|
|
return null
|
|
}
|
|
})
|
|
)
|
|
})
|
|
})
|
|
|
|
// Wait for all post updates to complete
|
|
await Promise.all(updatePostPromises)
|
|
|
|
console.log('Updated all posts with groupId and visibility.')
|
|
} catch (error) {
|
|
console.error('Error updating posts:', error)
|
|
}
|
|
}
|
|
|
|
updatePostsWithGroupIdAndVisibility()
|
|
}
|