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