mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2026-03-10 13:15:05 +00:00
delete topic fully works
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
/* eslint-disable promise/always-return */
|
||||
/* eslint-disable promise/always-return */
|
||||
const { admin, db } = require("../util/admin");
|
||||
exports.putTopic = (req, res) => {
|
||||
const newTopic = {
|
||||
topic: req.body.topic,
|
||||
topicId: null
|
||||
topic: req.body.topic
|
||||
};
|
||||
|
||||
admin
|
||||
@@ -12,12 +11,11 @@ exports.putTopic = (req, res) => {
|
||||
.add(newTopic)
|
||||
.then(doc => {
|
||||
const resTopic = newTopic;
|
||||
newTopic.topicId = doc.id;
|
||||
return res.status(200).json(resTopic);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
return res.status(500).json({ error: "something is wrong" });
|
||||
return res.status(500).json({ error: "something is wrong" });
|
||||
});
|
||||
};
|
||||
|
||||
@@ -29,13 +27,16 @@ exports.getAllTopics = (req, res) => {
|
||||
.then(data => {
|
||||
let topics = [];
|
||||
data.forEach(function(doc) {
|
||||
topics.push(doc.data());
|
||||
topics.push({
|
||||
topic: doc.data().topic,
|
||||
id: doc.id
|
||||
});
|
||||
});
|
||||
return res.status(200).json(topics);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
return res.status(500).json({ error: "Failed to fetch all topics." });
|
||||
return res.status(500).json({ error: "Failed to fetch all topics." });
|
||||
});
|
||||
};
|
||||
|
||||
@@ -45,16 +46,16 @@ exports.deleteTopic = (req, res) => {
|
||||
.get()
|
||||
.then(doc => {
|
||||
if (!doc.exists) {
|
||||
return res.status(404).json({ error: "Topic not found" });
|
||||
return res.status(404).json({ error: "Topic not found" });
|
||||
} else {
|
||||
return topic.delete();
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
res.json({ message: "Topic successfully deleted!" });
|
||||
res.json({ message: "Topic successfully deleted!" });
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
return res.status(500).json({ error: "Failed to delete topic." });
|
||||
return res.status(500).json({ error: "Failed to delete topic." });
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user