-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Show whether I have voted a proposal on the list page, #1075 * Simplify, #1075 * fix, #1075 * Update error text, #1075
- Loading branch information
Showing
5 changed files
with
115 additions
and
4 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
backend/packages/backend/src/features/proposals/commonRoutes.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
const Router = require("koa-router"); | ||
const { getProposalById } = require("./getProposalById"); | ||
const { getUserVotesOfProposals } = require("./getUserVotesOfProposals"); | ||
|
||
const router = new Router(); | ||
router.get("/proposal/:proposalId", getProposalById); | ||
router.get("/votes", getUserVotesOfProposals); | ||
|
||
module.exports = router; |
35 changes: 35 additions & 0 deletions
35
backend/packages/backend/src/features/proposals/getUserVotesOfProposals.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const { HttpError } = require("../../exc"); | ||
const { getVoteCollection } = require("../../mongo"); | ||
|
||
async function getUserVotesOfProposals(ctx) { | ||
const { network, address, proposal_cid: proposalCid } = ctx.query; | ||
|
||
if (!proposalCid) { | ||
throw new HttpError(400, "Query parameter proposal cid is required"); | ||
} | ||
|
||
if (!network) { | ||
throw new HttpError(400, "Query parameter network is required"); | ||
} | ||
|
||
if (!address) { | ||
throw new HttpError(400, "Query parameter address is required"); | ||
} | ||
|
||
const proposalCids = proposalCid.split(","); | ||
|
||
const q = { | ||
"data.proposalCid": { $in: proposalCids }, | ||
voter: address, | ||
voterNetwork: network, | ||
}; | ||
|
||
const voteCol = await getVoteCollection(); | ||
const votes = await voteCol.find(q).toArray(); | ||
|
||
ctx.body = votes; | ||
} | ||
|
||
module.exports = { | ||
getUserVotesOfProposals, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.