added folders to organize files

This commit is contained in:
Leon Liang
2019-09-26 01:54:51 -04:00
parent 8fa03700b1
commit 70037a5342
8 changed files with 137 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
/* eslint-disable promise/always-return */
exports.putPost = (req, res) => {
if (req.body.body.trim() === '') {
return res.status(400).json({ body: 'Body must not be empty!'});
}
const newPost = {
body: req.body.body,
userHandle: req.user.handle,
userImage: req.user.imageUrl,
createdAt: new Date().toISOString(),
likeCount: 0,
commentCount: 0
};
db.collection('post').add(newPost)
.then((doc) => {
const resPost = newPost;
resPost.postId = doc.id;
res.json(resPost);
})
.catch((err) => {
res.status(500).json({ error: 'something is wrong'});
console.error(err);
});
};