mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2026-03-10 13:15:05 +00:00
Reformat code
This commit is contained in:
@@ -1,52 +1,60 @@
|
||||
/* eslint-disable promise/always-return */
|
||||
const { admin, db } = require("../util/admin");
|
||||
exports.putTopic = (req, res) => {
|
||||
const newTopic = {
|
||||
topic: req.body.topic,
|
||||
topicId: null
|
||||
};
|
||||
|
||||
const newTopic = {
|
||||
topic: req.body.topic
|
||||
};
|
||||
|
||||
admin.firestore().collection('topics').add(newTopic)
|
||||
.then((doc) => {
|
||||
const resTopic = newTopic;
|
||||
newTopic.topicId = doc.id;
|
||||
return res.status(200).json(resTopic);
|
||||
admin
|
||||
.firestore()
|
||||
.collection("topics")
|
||||
.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'});
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
return res.status(500).json({ error: "something is wrong" });
|
||||
});
|
||||
};
|
||||
|
||||
exports.getAllTopics = (req, res) => {
|
||||
admin.firestore().collection('topics').get()
|
||||
.then((data) => {
|
||||
let topics = [];
|
||||
data.forEach(function(doc) {
|
||||
topics.push(doc.data());
|
||||
});
|
||||
return res.status(200).json(topics);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
return res.status(500).json({error: 'Failed to fetch all topics.'})
|
||||
admin
|
||||
.firestore()
|
||||
.collection("topics")
|
||||
.get()
|
||||
.then(data => {
|
||||
let topics = [];
|
||||
data.forEach(function(doc) {
|
||||
topics.push(doc.data());
|
||||
});
|
||||
return res.status(200).json(topics);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
return res.status(500).json({ error: "Failed to fetch all topics." });
|
||||
});
|
||||
};
|
||||
|
||||
exports.deleteTopic = (req, res) => {
|
||||
const topic = db.doc(`/topics/${req.params.topicId}`);
|
||||
topic.get().then((doc) => {
|
||||
if (!doc.exists) {
|
||||
return res.status(404).json({error: 'Topic not found'});
|
||||
} else {
|
||||
return topic.delete();
|
||||
}
|
||||
const topic = db.doc(`/topics/${req.params.topicId}`);
|
||||
topic
|
||||
.get()
|
||||
.then(doc => {
|
||||
if (!doc.exists) {
|
||||
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.'})
|
||||
})
|
||||
}
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
return res.status(500).json({ error: "Failed to delete topic." });
|
||||
});
|
||||
};
|
||||
|
||||
@@ -44,8 +44,7 @@ app.get("/user", fbAuth, getAuthenticatedUser);
|
||||
/*------------------------------------------------------------------*
|
||||
* handlers/post.js *
|
||||
*------------------------------------------------------------------*/
|
||||
const { getallPostsforUser, putPost
|
||||
} = require("./handlers/post");
|
||||
const { getallPostsforUser, putPost } = require("./handlers/post");
|
||||
|
||||
app.get("/getallPostsforUser", getallPostsforUser);
|
||||
|
||||
@@ -55,11 +54,7 @@ app.post("/putPost", fbAuth, putPost);
|
||||
/*------------------------------------------------------------------*
|
||||
* handlers/topic.js *
|
||||
*------------------------------------------------------------------*/
|
||||
const {
|
||||
putTopic,
|
||||
getAllTopics,
|
||||
deleteTopic
|
||||
} = require("./handlers/topic");
|
||||
const { putTopic, getAllTopics, deleteTopic } = require("./handlers/topic");
|
||||
|
||||
// add topic to database
|
||||
app.post("/putTopic", fbAuth, putTopic);
|
||||
|
||||
Reference in New Issue
Block a user