saved states of post for each user

This commit is contained in:
Aditya Sankaran
2019-11-29 20:18:51 -05:00
parent 0c9778949a
commit b83eb0c897
4 changed files with 56 additions and 18 deletions

View File

@@ -160,6 +160,24 @@ exports.quoteWithoutPost = (req, res) => {
}
exports.checkforLikePost = (req, res) => {
const likedPostDoc = admin.firestore().collection('likes').where('userHandle', '==', req.user.handle)
.where('postId', '==', req.params.postId).limit(1);
let result;
likedPostDoc.get()
.then((data) => {
if (data.empty) {
result = false;
return res.status(200).json(result);
}
else
{
result = true;
return res.status(200).json(result);
}
})
}
exports.likePost = (req, res) => {
let postData;
@@ -201,6 +219,7 @@ exports.likePost = (req, res) => {
}
exports.unlikePost = (req, res) => {
let postData;

View File

@@ -70,7 +70,7 @@ app.post("/removeSub", fbAuth, removeSub);
/*------------------------------------------------------------------*
* handlers/post.js *
*------------------------------------------------------------------*/
const { getallPostsforUser, getallPosts, putPost, likePost, unlikePost, quoteWithPost, quoteWithoutPost} = require("./handlers/post");
const { getallPostsforUser, getallPosts, putPost, likePost, unlikePost, quoteWithPost, quoteWithoutPost, checkforLikePost} = require("./handlers/post");
app.get("/getallPostsforUser", fbAuth, getallPostsforUser);
@@ -81,6 +81,7 @@ app.post("/putPost", fbAuth, putPost);
app.get("/like/:postId", fbAuth, likePost);
app.get("/unlike/:postId", fbAuth, unlikePost);
app.get("/checkforLikePost/:postId", fbAuth, checkforLikePost);
app.post("/quoteWithPost/:postId", fbAuth, quoteWithPost);
app.post("/quoteWithoutPost/:postId", fbAuth, quoteWithoutPost);