Re-get contracts to get updated links

This commit is contained in:
Ian Philips 2022-07-22 16:40:37 -06:00
parent 5f074206de
commit abde013ab6

View File

@ -12,13 +12,21 @@ const adminFirestore = admin.firestore()
const addGroupIdToContracts = async () => { const addGroupIdToContracts = async () => {
const groups = await getValues<Group>(adminFirestore.collection('groups')) const groups = await getValues<Group>(adminFirestore.collection('groups'))
const contracts = await getValues<Contract>(
adminFirestore.collection('contracts')
)
for (const group of groups) { for (const group of groups) {
const contracts = await getValues<Contract>(
adminFirestore
.collection('contracts')
.where('groupSlugs', 'array-contains', group.slug)
)
const groupContracts = contracts.filter((contract) => const groupContracts = contracts.filter((contract) =>
group.contractIds.includes(contract.id) group.contractIds.includes(contract.id)
) )
if (groupContracts.length !== contracts.length)
console.log(
`Found ${groupContracts.length} contracts for group ${group.slug}`
)
for (const contract of groupContracts) { for (const contract of groupContracts) {
const oldGroupLinks = contract.groupLinks?.filter( const oldGroupLinks = contract.groupLinks?.filter(
(l) => l.slug != group.slug (l) => l.slug != group.slug