From abde013ab6339dd3517e27fc4cadb42ad39da8c9 Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Fri, 22 Jul 2022 16:40:37 -0600 Subject: [PATCH] Re-get contracts to get updated links --- functions/src/scripts/link-contracts-to-groups.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/functions/src/scripts/link-contracts-to-groups.ts b/functions/src/scripts/link-contracts-to-groups.ts index feda249e..a61c6c6c 100644 --- a/functions/src/scripts/link-contracts-to-groups.ts +++ b/functions/src/scripts/link-contracts-to-groups.ts @@ -12,13 +12,21 @@ const adminFirestore = admin.firestore() const addGroupIdToContracts = async () => { const groups = await getValues(adminFirestore.collection('groups')) - const contracts = await getValues( - adminFirestore.collection('contracts') - ) + for (const group of groups) { + const contracts = await getValues( + adminFirestore + .collection('contracts') + .where('groupSlugs', 'array-contains', group.slug) + ) const groupContracts = contracts.filter((contract) => 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) { const oldGroupLinks = contract.groupLinks?.filter( (l) => l.slug != group.slug