Fixed having multiple return statements in post.js

This commit is contained in:
Clayton Wilson 2019-12-02 15:47:26 -05:00
parent cff0fd4e05
commit 7c7256acbd

View File

@ -40,31 +40,30 @@ exports.getallPostsforUser = (req, res) => {
}); });
return res.status(200).json(posts); return res.status(200).json(posts);
}) })
.then(function() { // .then(function() {
return res.status(200).json("Successfully retrieved all user's posts from database."); // return res.status(200).json("Successfully retrieved all user's posts from database.");
// })
})
.catch(function(err) { .catch(function(err) {
return res.status(500).json("Failed to retrieve user's posts from database.", err); return res.status(500).json(`Failed to retrieve user's posts from database.\n${err}`);
}); });
}; };
exports.getallPosts = (req, res) => { exports.getallPosts = (req, res) => {
var post_query = admin.firestore().collection("posts"); var post_query = admin.firestore().collection("posts");
post_query.get() post_query.get()
.then(function(allPosts) { .then(function(allPosts) {
let posts = []; let posts = [];
allPosts.forEach(function(doc) { allPosts.forEach(function(doc) {
posts.push(doc.data()); posts.push(doc.data());
});
return res.status(200).json(posts);
})
// .then(function() {
// return res.status(200).json("Successfully retrieved every post from database.");
// })
.catch(function(err) {
return res.status(500).json(`Failed to retrieve posts from database.\n ${err}`);
}); });
return res.status(200).json(posts);
})
.then(function() {
return res.status(200).json("Successfully retrieved every post from database.");
})
.catch(function(err) {
return res.status(500).json("Failed to retrieve posts from database.", err);
});
}; };
exports.quoteWithPost = (req, res) => { exports.quoteWithPost = (req, res) => {