mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 10:18:48 +00:00
Added getAllPosts
This commit is contained in:
parent
d6a0b0b1bc
commit
3f3a93be8c
@ -42,3 +42,29 @@ exports.getallPostsforUser = (req, res) => {
|
||||
return res.status(500).json({error: 'Failed to fetch all posts written by specific user.'})
|
||||
})
|
||||
};
|
||||
|
||||
exports.getAllPosts = (req, res) => {
|
||||
db.collection('posts')
|
||||
.orderBy('createdAt', 'desc')
|
||||
.get()
|
||||
.then((data) => {
|
||||
let posts = [];
|
||||
data.forEach((doc) => {
|
||||
posts.push({
|
||||
body: doc.data().body,
|
||||
userHandle: doc.data().userHandle,
|
||||
createdAt: doc.data().createdAt,
|
||||
commentCount: doc.data().commentCount,
|
||||
likeCount: doc.data().likeCount,
|
||||
userImage: doc.data().userImage,
|
||||
microBlogTitle: doc.data().microBlogTitle,
|
||||
microBlogTopics: doc.data().microBlogTopics,
|
||||
});
|
||||
});
|
||||
return res.json(posts);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
res.status(500).json({ error: err.code });
|
||||
});
|
||||
};
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint-disable prefer-arrow-callback */
|
||||
/* eslint-disable promise/always-return */
|
||||
const admin = require('firebase-admin');
|
||||
exports.putTopic = (req, res) => {
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint-disable prefer-arrow-callback */
|
||||
/* eslint-disable promise/catch-or-return */
|
||||
|
||||
const { admin, db } = require("../util/admin");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user