mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 10:18:48 +00:00
Fixing some issues with retrieving posts
This commit is contained in:
parent
2fc37e3e34
commit
7341de742e
@ -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 });
|
||||
});
|
||||
};
|
||||
@ -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 *
|
||||
|
||||
@ -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}/>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user