diff --git a/database/handler.js b/database/handler.js index 967a7e16..11d46f5e 100644 --- a/database/handler.js +++ b/database/handler.js @@ -362,6 +362,14 @@ async function getNewsletterCount () { return newsletterCounts; } +async function getSubmissions () { + return await Submission.find().lean(); +} + +async function deleteSubmission (link) { + const sub = await Submission.findOneAndDelete({ link: link }); + return sub; +} module.exports = { createNewUser, @@ -396,5 +404,7 @@ module.exports = { addTeam, addSubmission, updateNewsletterCount, - getNewsletterCount + getNewsletterCount, + getSubmissions, + deleteSubmission }; diff --git a/routes/govportal.js b/routes/govportal.js index 8cbe55ec..2267c8a3 100644 --- a/routes/govportal.js +++ b/routes/govportal.js @@ -209,6 +209,22 @@ router.patch('/delete-option', async (req, res) => { } }); +router.get('/submission-management', async (req, res) => { + const submissions = await dbh.getSubmissions(); + return res.renderFile('govportal/submissions-management.njk', { submissions }); +}); + +router.post('/submission-management', async (req, res) => { + const data = req.body.data; + let response; + try { + response = await dbh.deleteSubmission(data); + return res.send({ success: true, message: 'Successfully deleted post', response: response }); + } catch (e) { + return res.send({ success: false, message: 'Something Went Wrong' }); + } +}); + module.exports = { route: '/gov-portal', router diff --git a/templates/govportal/govportal.njk b/templates/govportal/govportal.njk index 682218d7..45d4f524 100644 --- a/templates/govportal/govportal.njk +++ b/templates/govportal/govportal.njk @@ -14,6 +14,9 @@ },{ href: 'newsletter', name: 'Newsletter' +},{ + href: 'submission', + name: 'Submission' }] %} {% block navbar %} @@ -68,6 +71,7 @@ Add Poll Add Post View Newsletter Count + View Submissions {% endblock %} diff --git a/templates/govportal/submissions-management.njk b/templates/govportal/submissions-management.njk new file mode 100644 index 00000000..35b6002d --- /dev/null +++ b/templates/govportal/submissions-management.njk @@ -0,0 +1,198 @@ +{% extends "govportal/govportal.njk" %} + +{% set thispage = 'Submission' %} +{% set pagetitle = 'Governor Portal | Submission Management' %} +{% set actionname = 'Submission Management' %} + +{% set scripts = ['https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js'] %} + +{% block actioncontent %} + + {% for submission in submissions %} +
+
+ {% for key, value in submission %} + {% if key != '_id' and key != '__v' and key != 'metadata' %} + {{ key | capitalize }}: {% if key != 'date' %} {{ value }} {% else %} {{ value | string | truncate(15, true, "") }} {% endif %}
+ {% endif %} + {% endfor %} +
+ +
+ +
+
+ {% endfor %} + +{% endblock %} + +{% block customcss %} + {{ super() }} + +{% endblock %} + +{% block customjs %} + +{% endblock %}