Skip to content

Commit

Permalink
Modified how you get all the votes
Browse files Browse the repository at this point in the history
  • Loading branch information
EchoSkorJjj committed Nov 5, 2023
1 parent aa33820 commit bab84a2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
18 changes: 14 additions & 4 deletions client/src/pages/VotingTally.jsx
Original file line number Diff line number Diff line change
@@ -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('');
Expand All @@ -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`);
Expand Down
15 changes: 15 additions & 0 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({});
Expand Down

0 comments on commit bab84a2

Please sign in to comment.