Fix /api/is-unlock-blocked for new partials location

This commit is contained in:
David Ernst
2024-08-15 05:04:50 -07:00
parent 7e47ac78b7
commit 92dcd66fc0

View File

@@ -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
})