added get request userline function

This commit is contained in:
Aditya Sankaran
2019-10-01 14:03:15 -04:00
parent 7969d3b10b
commit 754c2f2d75
4 changed files with 42 additions and 9 deletions

View File

@@ -26,3 +26,20 @@ exports.putPost = (req, res) => {
});
};
exports.getallPostsforUser = (req, res) => {
admin.firestore().collection('posts').where('userHandle', '==', 'user' ).get()
.then((data) => {
let posts = [];
data.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.'})
})
}