Remove member and contract ids from group doc

This commit is contained in:
Ian Philips 2022-09-06 08:14:13 -06:00
parent 39d7f1055b
commit 2ee067c072
2 changed files with 15 additions and 6 deletions

View File

@ -12,10 +12,6 @@ export type Group = {
aboutPostId?: string aboutPostId?: string
chatDisabled?: boolean chatDisabled?: boolean
mostRecentContractAddedTime?: number mostRecentContractAddedTime?: number
/** @deprecated - members and contracts now stored as subcollections*/
memberIds?: string[] // Deprecated
/** @deprecated - members and contracts now stored as subcollections*/
contractIds?: string[] // Deprecated
} }
export const MAX_GROUP_NAME_LENGTH = 75 export const MAX_GROUP_NAME_LENGTH = 75
export const MAX_ABOUT_LENGTH = 140 export const MAX_ABOUT_LENGTH = 140

View File

@ -86,7 +86,7 @@ async function convertGroupFieldsToGroupDocuments() {
} }
} }
} }
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async function updateTotalContractsAndMembers() { async function updateTotalContractsAndMembers() {
const groups = await getGroups() const groups = await getGroups()
for (const group of groups) { for (const group of groups) {
@ -101,9 +101,22 @@ async function updateTotalContractsAndMembers() {
}) })
} }
} }
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async function removeUnusedMemberAndContractFields() {
const groups = await getGroups()
for (const group of groups) {
log('removing member and contract ids', group.slug)
const groupRef = admin.firestore().collection('groups').doc(group.id)
await groupRef.update({
memberIds: admin.firestore.FieldValue.delete(),
contractIds: admin.firestore.FieldValue.delete(),
})
}
}
if (require.main === module) { if (require.main === module) {
initAdmin() initAdmin()
// convertGroupFieldsToGroupDocuments() // convertGroupFieldsToGroupDocuments()
updateTotalContractsAndMembers() // updateTotalContractsAndMembers()
removeUnusedMemberAndContractFields()
} }