Fixing some issues with retrieving posts

This commit is contained in:
Clayton Wilson 2019-10-29 14:28:53 -04:00
parent 2fc37e3e34
commit 7341de742e
3 changed files with 9 additions and 7 deletions

View File

@ -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 });
});
};

View File

@ -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 *

View File

@ -94,13 +94,13 @@ class user extends Component {
) : (<p> loading topics...</p>);
let recentPostsMarkup = this.state.posts ? (
this.state.posts.map(post => <Posts post={post}/>)
this.state.posts.map(post => <Posts key={post.createdAt} post={post}/>)
) : ( <p> Loading... </p> );
return (
<Grid container spacing={16}>
<Grid item sm={8} xs={12}>
<p>Post</p>
{recentPostsMarkup}
</Grid>
<Grid item sm={4} xs={12}>
<img src={noImage}/>