diff --git a/client/src/pages/VotingTally.jsx b/client/src/pages/VotingTally.jsx index d4f9c66..5b31d33 100644 --- a/client/src/pages/VotingTally.jsx +++ b/client/src/pages/VotingTally.jsx @@ -1,10 +1,7 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import axios from 'axios'; -import * as bigintConversion from 'bigint-conversion'; -import * as paillierBigint from 'paillier-bigint' import Alice from '../assets/alice.png'; import Mallory from '../assets/mallory.png'; -import usePublicKeyStore from '../store/PublicKeyStore'; export default function VotingTally() { const [aliceStatus, setAliceStatus] = useState(''); @@ -20,6 +17,19 @@ export default function VotingTally() { const base_url = import.meta.env.VITE_NODE_ENV === 'production' ? import.meta.env.VITE_PRODUCTION_URL : import.meta.env.VITE_DEVELOPMENT_URL; + useEffect(() => { + async function getAllVotes() { + try { + const response = await axios.get(`${base_url}/getallvotes`); + const { allVotes } = response.data; + setAllVotes(allVotes); + } catch (error) { + console.error('Error fetching all votes:', error); + } + } + getAllVotes(); + }) + async function getTotalVote() { try { const response = await axios.get(`${base_url}/tally`); diff --git a/server/server.js b/server/server.js index d6f6c71..5584cf3 100644 --- a/server/server.js +++ b/server/server.js @@ -107,6 +107,21 @@ async function startServer() { } }); + app.get('/getallvotes', async (req, res) => { + try { + const users = await User.find({}); + const allVotes = users.map((user) => { + return { + name: user.name, + vote: user.vote + } + }); + res.status(200).json({allVotes: allVotes}); + } catch (error) { + res.status(500).json({ message: 'Error getting all votes' }); + } + }); + app.get('/tally', async (req, res) => { try { const users = await User.find({});