diff --git a/pages/api/election/[election_id]/admin/is-unlock-blocked.ts b/pages/api/election/[election_id]/admin/is-unlock-blocked.ts index 24b3a006..e6c1f8e9 100644 --- a/pages/api/election/[election_id]/admin/is-unlock-blocked.ts +++ b/pages/api/election/[election_id]/admin/is-unlock-blocked.ts @@ -18,6 +18,11 @@ export default async (req: NextApiRequest, res: NextApiResponse) => { // Begin preloading all these docs const loadTrustees = election.collection('trustees').orderBy('index', 'asc').get() + const loadTrusteePartials = Promise.all( + (await loadTrustees).docs.map(async (doc) => + (await doc.ref.collection('post-election-data').doc('partials').get()).data(), + ), + ) // Confirm they're a valid admin that created this election const jwt = await checkJwtOwnsElection(req, res, election_id) @@ -52,16 +57,17 @@ export default async (req: NextApiRequest, res: NextApiResponse) => { } return !waiting_on // Break out of loop when we find one }) - if (waiting_on) return res.status(206).send(waiting_on) + if (waiting_on) + return res.status(206).send(waiting_on) - // Check if any trustees haven't decrypted - trustees.every(({ email, partials }, index) => { + // Check if any trustees haven't decrypted + ;(await loadTrusteePartials).every((data, index) => { // Skip admin if (index === 0) return true - const num_decrypted = (partials || {})[first_col]?.length || 0 + const num_decrypted = (data?.partials || {})[first_col]?.length || 0 if (num_decrypted < num_admin_shuffled) { - waiting_on = email + waiting_on = trustees[index].email } return !waiting_on // Break out of loop when we find one })