mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-15 18:08:46 +00:00
Get user's posts works now
This commit is contained in:
parent
6db14e3868
commit
8438ce27cf
@ -27,16 +27,20 @@ exports.putPost = (req, res) => {
|
||||
};
|
||||
|
||||
exports.getallPostsforUser = (req, res) => {
|
||||
admin.firestore().collection('posts').where('userHandle', '==', req.userData.handle ).get()
|
||||
.then((data) => {
|
||||
var post_query = admin.firestore().collection("posts").where("userHandle", "==", req.user.handle);
|
||||
post_query.get()
|
||||
.then(function(myPosts) {
|
||||
let posts = [];
|
||||
data.forEach(function(doc) {
|
||||
myPosts.forEach(function(doc) {
|
||||
posts.push(doc.data());
|
||||
});
|
||||
return res.status(200).json(posts);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
return res.status(500).json({error: 'Failed to fetch all posts written by specific user.'})
|
||||
.then(function() {
|
||||
res.status(200).send("Successfully retrieved all user's posts from database.");
|
||||
return;
|
||||
})
|
||||
.catch(function(err) {
|
||||
res.status(500).send("Failed to retrieve all user's posts from database.", err);
|
||||
});
|
||||
};
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
/* eslint-disable promise/catch-or-return */
|
||||
|
||||
const { admin, db } = require("../util/admin");
|
||||
const config = require("../util/config");
|
||||
const { validateUpdateProfileInfo } = require("../util/validator");
|
||||
|
||||
@ -47,7 +47,7 @@ app.get("/user", fbAuth, getAuthenticatedUser);
|
||||
const { getallPostsforUser, putPost
|
||||
} = require("./handlers/post");
|
||||
|
||||
app.get("/getallPostsforUser", getallPostsforUser);
|
||||
app.get("/getallPostsforUser", fbAuth, getallPostsforUser);
|
||||
|
||||
// Adds one post to the database
|
||||
app.post("/putPost", fbAuth, putPost);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user