Skip to content

Commit

Permalink
Merge pull request #197 from kgpmask/query-params
Browse files Browse the repository at this point in the history
changed params to querystring
  • Loading branch information
Goose-Of-War authored Jun 25, 2023
2 parents 6d2e37c + 08e988e commit 54d2606
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions routes/govportal.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ router.get('/post-management', async (req, res) => {
const posts = (await dbh.getPosts().limit(20)).map(post => post.toObject());
return res.renderFile(`govportal/post-management.njk`, { posts });
});
router.get('/edit-post/:id', async (req, res) => {
const id = req.params.id;
router.get('/edit-post', async (req, res) => {
const id = req.query.id;
const data = (await dbh.getPost(id)).toObject();
return res.renderFile(`govportal/edit-post.njk`, { ...data, date: data.date.toISOString().slice(0, 10) });
});
Expand All @@ -43,8 +43,8 @@ router.get('/add-poll', (req, res) => {
return res.renderFile(`govportal/add-poll.njk`, { date: date.toISOString().slice(0, 10) });
});

router.get('/edit-poll/:id', async (req, res) => {
const id = req.params.id;
router.get('/edit-poll', async (req, res) => {
const id = req.query.id;
const poll = (await dbh.getPoll(id)).toObject();
return res.renderFile(`govportal/edit-poll.njk`, { ...poll, endTime: poll.endTime.toISOString().slice(0, 10) });
});
Expand Down
8 changes: 4 additions & 4 deletions routes/polls.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ const router = require('express').Router();
const dbh = require('../database/handler');

// Route for opening poll or poll list
router.get('/:pollId?', async (req, res) => {
router.get('/', async (req, res) => {
if (!req.loggedIn) return res.loginRedirect(req, res);
const pollId = req.params.pollId;
const pollId = req.query.id;
const activePolls = await dbh.getActivePolls();
if (!pollId) return res.renderFile('poll_list.njk', {
activePolls,
Expand Down Expand Up @@ -38,9 +38,9 @@ router.post('/', async (req, res) => {
});

// Route for displaying poll results
router.get('/results/:id?', async (req, res) => {
router.get('/results', async (req, res) => {
if (!req.loggedIn) return res.loginRedirect(req, res);
const pollId = req.params.id;
const pollId = req.query.id;
if (!pollId) return res.notFound('No ID given.');
const activePolls = await dbh.getActivePolls();
const poll = activePolls.find(poll => poll._id === pollId);
Expand Down
4 changes: 2 additions & 2 deletions templates/govportal/poll-management.njk
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@
}
}
async function editPoll (id) {
await axios.get(`/gov-portal/edit-poll/${id}`)
await axios.get(`/gov-portal/edit-poll?id=${id}`)
.then(res => {
window.location.href = `/gov-portal/edit-poll/${id}`;
window.location.href = `/gov-portal/edit-poll?id=${id}`;
});
}
function deletePoll (id) {
Expand Down
4 changes: 2 additions & 2 deletions templates/govportal/post-management.njk
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@
}
}
async function editPost (id) {
await axios.get(`/gov-portal/edit-post/${id}`)
await axios.get(`/gov-portal/edit-post?id=${id}`)
.then(res => {
window.location.href = `/gov-portal/edit-post/${id}`;
window.location.href = `/gov-portal/edit-post?id=${id}`;
});
}
function deletePost (link) {
Expand Down
4 changes: 2 additions & 2 deletions templates/poll_list.njk
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
<div class="poll">
<div class="title"> {{ poll.title }} </div>
<div class="buttons">
<button onclick="window.location.href = '/polls/{{ poll._id }}'">Vote</button>
<button onclick="window.location.href = '/polls/results/{{ poll._id }}'">Result</button>
<button onclick="window.location.href = '/polls?id={{ poll._id }}'">Vote</button>
<button onclick="window.location.href = '/polls/results?id={{ poll._id }}'">Result</button>
</div>
</div>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion templates/poll_vote.njk
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
setTimeout(function () {e.classList.add('hidden')}, 2000);
if (response.success) {
setTimeout(function () {
window.location.href = "/polls/results/{{ poll._id }}";
window.location.href = "/polls/results?id={{ poll._id }}";
}, 3000);
}
}
Expand Down

0 comments on commit 54d2606

Please sign in to comment.