Skip to content

Commit

Permalink
Changes after PR Review
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutoshpw committed Apr 21, 2024
1 parent b8eb2f3 commit 69357b5
Show file tree
Hide file tree
Showing 8 changed files with 649 additions and 1,577 deletions.
4 changes: 2 additions & 2 deletions components/polls/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ const addPoll = async (req, response) => {
return element._id;
});

const pollExists = await db_connect
const doesPollExists = await db_connect
.collection("Polls")
.findOne({ payloadBytes });

if (pollExists) {
if (doesPollExists) {
throw new Error("Invalid Signature, Poll already exists");
}

Expand Down
203 changes: 203 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "./server.js",
"scripts": {
"test": "jest",
"start":"node ./server.js",
"dev": "nodemon ./server.js"
},
"jest": {
Expand Down Expand Up @@ -33,6 +34,7 @@
"jest": "^29.7.0",
"jest-mock": "^29.7.0",
"mongodb-memory-server": "^9.1.4",
"nodemon": "^3.1.0",
"supertest": "^6.3.3"
}
}
3 changes: 2 additions & 1 deletion routes/tokens.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const express = require("express");
const {catchAsync} = require("../services/response.util");

// recordRoutes is an instance of the express router.
// We use it to define our routes.
Expand Down Expand Up @@ -87,6 +88,6 @@ tokensRoutes.route("/token/:id").get(getTokenById);
*/
tokensRoutes
.route("/network/:network/token/:address/token-id/:tokenID/voting-power")
.get(getVotingPowerAtLevel);
.get(catchAsync(getVotingPowerAtLevel));

module.exports = tokensRoutes;
2 changes: 1 addition & 1 deletion services/ipfs.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { NFTStorage } = require('nft.storage')
const NFT_STORAGE_KEY = AppConfig.IPFS.NFT_STORAGE_TOKEN

async function uploadToIPFS(jsonData) {
const data = new Blob([jsonData])
const data = new Blob([jsonData], { type: 'text/plain' })
const client = new NFTStorage({ token: NFT_STORAGE_KEY })
const cid = await client.storeBlob(data)
return cid
Expand Down
34 changes: 34 additions & 0 deletions services/response.util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const catchAsync = (fn) => (req, res, next) => {
Promise.resolve(fn(req, res, next)).catch((err) => {
const errName = err.name
const errMessage = err.message;

console.error({ errName })
if (!errMessage) errMessage = err;


console.error('CaughtError:', err);
console.error('ErrorStack:', err.stack)
console.error('ErrorPayload:', JSON.stringify(req.body));
console.error('ErrorParams:', req.params);
console.error('--------------------xxxxxx--------------------');
console.error(err.stack)

let responseStatusCode = 500;
if (err.statusCode) responseStatusCode = err.statusCode

try {
errMessage = JSON.parse(errMessage)
errMessage = errMessage.map(ex => ex.message).join(",")
} catch (e) { }

return res.status(responseStatusCode).json({
success: false,
message: errMessage,
});
});
};

module.exports = {
catchAsync
}
Loading

0 comments on commit 69357b5

Please sign in to comment.