diff --git a/controllers/main.js b/controllers/main.js
index 7ac651d..34be0f7 100644
--- a/controllers/main.js
+++ b/controllers/main.js
@@ -166,9 +166,23 @@ const newProject = async (req, res) => {
}
}
+const newFaq = async (req, res) => {
+ if (req.body.auth === process.env.AUTH_KEY) {
+ const faq = {
+ question: req.body.question,
+ answer: req.body.answer
+ }
+
+ await Faq.insertMany(faq);
+ res.sendStatus(200);
+ } else {
+ res.sendStatus(401);
+ }
+}
+
const deleteEvent = async (req, res) => {
if (req.body.auth === process.env.AUTH_KEY) {
- await Event.findOneAndDelete({ name: req.body.name });
+ await Event.findByIdAndDelete(req.body.id);
res.sendStatus(200);
} else {
res.sendStatus(401);
@@ -177,7 +191,7 @@ const deleteEvent = async (req, res) => {
const deleteCourse = async (req, res) => {
if (req.body.auth === process.env.AUTH_KEY) {
- await Course.findOneAndDelete({ name: req.body.name });
+ await Course.findByIdAndDelete(req.body.id);
res.sendStatus(200);
} else {
res.sendStatus(401);
@@ -186,7 +200,16 @@ const deleteCourse = async (req, res) => {
const deleteProject = async (req, res) => {
if (req.body.auth === process.env.AUTH_KEY) {
- await Project.findOneAndDelete({ name: req.body.name });
+ await Project.findByIdAndDelete(req.body.id);
+ res.sendStatus(200);
+ } else {
+ res.sendStatus(401);
+ }
+}
+
+const deleteFaq = async (req, res) => {
+ if (req.body.auth === process.env.AUTH_KEY) {
+ await Faq.findByIdAndDelete(req.body.id);
res.sendStatus(200);
} else {
res.sendStatus(401);
@@ -205,7 +228,7 @@ const updateEvent = async (req, res) => {
duration: req.body.duration
}
- await Event.findOneAndUpdate({ name: req.body.name }, event, { runValidators: true, new: true });
+ await Event.findByIdAndUpdate(req.body.id, event, { runValidators: true, new: true });
res.sendStatus(200);
} else {
res.sendStatus(401);
@@ -225,7 +248,7 @@ const updateCourse = async (req, res) => {
duration: req.body.duration
}
- await Course.findOneAndUpdate({ name: req.body.name }, course, { runValidators: true, new: true });
+ await Course.findByIdAndUpdate(req.body.id, course, { runValidators: true, new: true });
res.sendStatus(200);
} else {
res.sendStatus(401);
@@ -242,7 +265,21 @@ const updateProject = async (req, res) => {
repository: req.body.repository
}
- await Project.findOneAndUpdate({ name: req.body.name }, project, { runValidators: true, new: true });
+ await Project.findByIdAndUpdate(req.body.id, project, { runValidators: true, new: true });
+ res.sendStatus(200);
+ } else {
+ res.sendStatus(401);
+ }
+}
+
+const updateFaq = async (req, res) => {
+ if (req.body.auth === process.env.AUTH_KEY) {
+ const faq = {
+ question: req.body.question,
+ answer: req.body.answer
+ }
+
+ await Faq.findByIdAndUpdate(req.body.id, faq, { runValidators: true, new: true });
res.sendStatus(200);
} else {
res.sendStatus(401);
@@ -258,6 +295,7 @@ const getMembers = async (req, res) => {
csv += `${member.firstName},${member.lastName},${member.studentID},${member.degree},${member.email},${member.department},${member.mobileNumber},${member.groupChat}`;
csv += "\r\n";
}
+
res.send(csv);
} else {
res.sendStatus(401);
@@ -282,11 +320,14 @@ module.exports = {
newEvent,
newCourse,
newProject,
+ newFaq,
deleteEvent,
deleteCourse,
deleteProject,
+ deleteFaq,
updateEvent,
updateCourse,
updateProject,
+ updateFaq,
getMembers
}
diff --git a/routes/main.js b/routes/main.js
index b24ec69..b359ad7 100644
--- a/routes/main.js
+++ b/routes/main.js
@@ -19,14 +19,17 @@ router.post('/idea', controller.shareIdea);
router.post('/event', controller.newEvent);
router.post('/course', controller.newCourse);
router.post('/arge', controller.newProject);
+router.post('/faq', controller.newFaq);
router.delete('/event', controller.deleteEvent);
router.delete('/course', controller.deleteCourse);
router.delete('/arge', controller.deleteProject);
+router.delete('/faq', controller.deleteFaq);
router.patch('/event', controller.updateEvent);
router.patch('/course', controller.updateCourse);
router.patch('/arge', controller.updateProject);
+router.patch('/faq', controller.updateFaq);
module.exports = router;
diff --git a/views/sections/arge.ejs b/views/sections/arge.ejs
index f61743a..58ea3ef 100644
--- a/views/sections/arge.ejs
+++ b/views/sections/arge.ejs
@@ -79,6 +79,7 @@
+ <%= project._id.toString() %>
<% } %>
diff --git a/views/sections/events.ejs b/views/sections/events.ejs
index 829a2c9..b2d4906 100644
--- a/views/sections/events.ejs
+++ b/views/sections/events.ejs
@@ -64,6 +64,7 @@
+ <%= event._id.toString() %>
<% } %>
@@ -145,6 +146,7 @@
+ <%= course._id.toString() %>
<% } %>
diff --git a/views/sections/faq.ejs b/views/sections/faq.ejs
index 8c5a9f5..e676683 100644
--- a/views/sections/faq.ejs
+++ b/views/sections/faq.ejs
@@ -26,6 +26,7 @@
+ <%= faq._id.toString() %>