Skip to content

Commit

Permalink
Temp Removed IPFS
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutoshpw committed Jun 19, 2024
1 parent a332836 commit 40fe484
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ yarn-error.log*

.idea
.cosine
yarn.lock
yarn.lock
test.js
.vscode
27 changes: 15 additions & 12 deletions components/choices/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const updateChoiceById = async (req, response) => {
const isVoted = await db_connect
.collection('Choices')
.find({
pollID: poll._id,
pollID: poll._id,
walletAddresses: { $elemMatch: { address: address } },
})
.toArray();
Expand All @@ -135,14 +135,16 @@ const updateChoiceById = async (req, response) => {
}
}

const cidLink = await uploadToIPFS(
getIPFSProofFromPayload(payloadBytes, signature)
);
if (!cidLink) {
throw new Error(
"Could not upload proof to IPFS, Vote was not registered. Please try again later"
);
}
// const ipfsProof = getIPFSProofFromPayload(payloadBytes, signature)
// const cidLink = await uploadToIPFS(ipfsProof).catch(error => {
// console.error('IPFS Error', error)
// return null;
// });
// if (!cidLink) {
// throw new Error(
// "Could not upload proof to IPFS, Vote was not registered. Please try again later"
// );
// }

// TODO: Optimize this Promise.all
await Promise.all(
Expand All @@ -157,7 +159,8 @@ const updateChoiceById = async (req, response) => {
signature,
};

walletVote.cidLink = cidLink;
// TODO: Enable this when the IPFS CID is added to the walletVote object
// walletVote.cidLink = cidLink;

const choice = await db_connect
.collection("Choices")
Expand Down Expand Up @@ -186,7 +189,7 @@ const updateChoiceById = async (req, response) => {
const coll1 = db_connect.collection("Choices");
// const coll2 = db_connect.collection("Polls");


// Important:: You must pass the session to the operations
await coll1.updateOne(
{ _id: ObjectId(oldVote._id) },
Expand Down Expand Up @@ -285,7 +288,7 @@ const updateChoiceById = async (req, response) => {

response.json({ success: true });
} catch (error) {
console.log("error: ", error.message);
console.log("error: ", error);
response.status(400).send({
message: error.message,
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "./server.js",
"scripts": {
"test": "jest",
"start":"node ./server.js",
"start": "node ./server.js",
"dev": "nodemon ./server.js"
},
"jest": {
Expand Down

0 comments on commit 40fe484

Please sign in to comment.