diff --git a/functions/handlers/post.js b/functions/handlers/post.js index 19753bc..35c38df 100644 --- a/functions/handlers/post.js +++ b/functions/handlers/post.js @@ -1,6 +1,8 @@ /* eslint-disable prefer-arrow-callback */ /* eslint-disable promise/always-return */ -const admin = require('firebase-admin'); +const { admin, db } = require("../util/admin"); + + exports.putPost = (req, res) => { const newPost = { @@ -29,7 +31,7 @@ exports.putPost = (req, res) => { }; exports.getallPostsforUser = (req, res) => { - admin.firestore().collection('posts').where('userHandle', '==', 'new user' ).get() + db.collection('posts').where('userHandle', '==', 'new user' ).get() .then((data) => { let posts = []; data.forEach(function(doc) { @@ -61,10 +63,10 @@ exports.getAllPosts = (req, res) => { microBlogTopics: doc.data().microBlogTopics, }); }); - return res.json(posts); + return res.status(200).json(posts); }) .catch((err) => { console.error(err); - res.status(500).json({ error: err.code }); + return res.status(500).json({ error: err.code }); }); }; \ No newline at end of file diff --git a/functions/index.js b/functions/index.js index 97ab31b..df4f6e4 100644 --- a/functions/index.js +++ b/functions/index.js @@ -53,7 +53,7 @@ app.get("/getallPostsforUser", getallPostsforUser); app.post("/putPost", fbAuth, putPost); // Displays posts on home page -app.post("/getAllPosts", getAllPosts ); +app.get("/getAllPosts", getAllPosts ); /*------------------------------------------------------------------* * handlers/topic.js * diff --git a/twistter-frontend/src/pages/user.js b/twistter-frontend/src/pages/user.js index 7ea0871..34627c9 100644 --- a/twistter-frontend/src/pages/user.js +++ b/twistter-frontend/src/pages/user.js @@ -94,13 +94,13 @@ class user extends Component { ) : (
loading topics...
); let recentPostsMarkup = this.state.posts ? ( - this.state.posts.map(post =>Loading...
); return (Post
+ {recentPostsMarkup}