mirror of
https://github.com/siv-org/siv.git
synced 2026-01-10 10:57:59 -05:00
/trustee: Fix accessing partials on the frontned
This commit is contained in:
@@ -5,7 +5,7 @@ import { PartialWithProof } from 'src/trustee/trustee-state'
|
||||
import { transform_email_keys } from './commafy'
|
||||
|
||||
export type TrusteesLatestPartials = {
|
||||
trustees: Array<{ email: string; index: number; partials?: Record<string, PartialWithProof[]> }>
|
||||
trustees: Array<{ email: string; index: number; partials?: Record<string, { partials: PartialWithProof[] }> }>
|
||||
}
|
||||
|
||||
export default async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
@@ -25,8 +25,8 @@ export default async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
|
||||
// Get partials from separate sub-docs
|
||||
const partialDocs = await doc.ref.collection('partials').get()
|
||||
const partials = {} as Record<string, PartialWithProof[]>
|
||||
partialDocs.docs.forEach((doc) => (partials[doc.id] = doc.data() as PartialWithProof[]))
|
||||
const partials = {} as Record<string, { partials: PartialWithProof[] }>
|
||||
partialDocs.docs.forEach((doc) => (partials[doc.id] = doc.data() as { partials: PartialWithProof[] }))
|
||||
|
||||
const public_data: Record<string, unknown> = {
|
||||
email: trusteeData.email,
|
||||
|
||||
@@ -152,7 +152,8 @@ export const VotesToDecrypt = ({
|
||||
<h3>IV. Votes to Decrypt</h3>
|
||||
<ol className="pl-5">
|
||||
{trustees?.map(({ email, you }) => {
|
||||
const partials = partialsByEmail[email]
|
||||
const partials = partialsByEmail[email] || {}
|
||||
|
||||
return (
|
||||
<li className="mb-8" key={email}>
|
||||
{/* Top row */}
|
||||
@@ -160,7 +161,7 @@ export const VotesToDecrypt = ({
|
||||
{/* Left */}
|
||||
<span>
|
||||
{email}
|
||||
{you && <YouLabel />} partially decrypted {!partials ? 0 : Object.values(partials)[0]?.length}
|
||||
{you && <YouLabel />} partially decrypted {!partials ? 0 : Object.values(partials)[0]?.length || 0}
|
||||
votes.
|
||||
</span>
|
||||
{/* Right */}
|
||||
|
||||
@@ -41,10 +41,19 @@ export function useLatestPartials(election_id?: string) {
|
||||
}, [election_id, mutate])
|
||||
|
||||
const partialsByEmail =
|
||||
data?.trustees?.reduce<Record<string, Record<string, PartialWithProof[]> | undefined>>(
|
||||
(memo, trustee) => ({ ...memo, [trustee.email]: trustee.partials }),
|
||||
{},
|
||||
) || {}
|
||||
data?.trustees?.reduce<Record<string, Record<string, PartialWithProof[]> | undefined>>((memo, trustee) => {
|
||||
if (!trustee.partials) return memo
|
||||
|
||||
// Transform from Record<string, { partials: PartialWithProof[] }> to Record<string, PartialWithProof[]>
|
||||
// by unwrapping the { partials: [...] } structure
|
||||
const unwrappedPartials: Record<string, PartialWithProof[]> = {}
|
||||
Object.entries(trustee.partials).forEach(([column, wrapped]) => {
|
||||
if (wrapped && typeof wrapped === 'object' && 'partials' in wrapped) {
|
||||
unwrappedPartials[column] = (wrapped as { partials: PartialWithProof[] }).partials
|
||||
}
|
||||
})
|
||||
return { ...memo, [trustee.email]: unwrappedPartials }
|
||||
}, {}) || {}
|
||||
|
||||
return { partialsByEmail }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user