Unreact to comments
This commit is contained in:
@@ -90,11 +90,11 @@ postDB = (DB)=>{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
DB.newCommentReaction = (postid, commentDate, userid, reaction) => {
|
DB.newCommentReaction = (postid, commentDate, profileid, reaction) => {
|
||||||
const id = DB.ObjectID(postid);
|
const id = DB.ObjectID(postid);
|
||||||
let update = {
|
let update = {
|
||||||
$set:{
|
$set:{
|
||||||
["comments.$.reactions." + userid]: reaction,
|
["comments.$.reactions." + profileid]: reaction,
|
||||||
"comments.$.lastUpdated": new Date(),
|
"comments.$.lastUpdated": new Date(),
|
||||||
lastUpdated: new Date()
|
lastUpdated: new Date()
|
||||||
}
|
}
|
||||||
@@ -108,6 +108,26 @@ postDB = (DB)=>{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DB.removeCommentReaction = (postid, commentDate, profileid) => {
|
||||||
|
const id = DB.ObjectID(postid);
|
||||||
|
let update = {
|
||||||
|
$unset:{
|
||||||
|
["comments.$.reactions." + profileid]: '',
|
||||||
|
"comments.$.lastUpdated": new Date(),
|
||||||
|
},
|
||||||
|
$set: {
|
||||||
|
lastUpdated: new Date()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DB.postCols.updateOne({
|
||||||
|
_id: id,
|
||||||
|
"comments.createdAt": commentDate
|
||||||
|
}, update).catch((err)=>{
|
||||||
|
console.log(err);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
DB.getPosts = async (profileId, viewerProfileId) => {
|
DB.getPosts = async (profileId, viewerProfileId) => {
|
||||||
const profile = await DB.getProfile(viewerProfileId);
|
const profile = await DB.getProfile(viewerProfileId);
|
||||||
let query = {};
|
let query = {};
|
||||||
|
|||||||
@@ -218,6 +218,16 @@ DB.getDB.then((DB) => {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.post("/comment/unreact", async (req, res) => {
|
||||||
|
let profileid = getProfileId(req);
|
||||||
|
let postid = req.body.postid;
|
||||||
|
let commentDate = new Date(req.body.commentDate);
|
||||||
|
r = await DB.removeCommentReaction(postid, commentDate, profileid);
|
||||||
|
return res.json({
|
||||||
|
status: "ok"
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
router.get("/:id", async (req, res) => {
|
router.get("/:id", async (req, res) => {
|
||||||
const postId = req.params.id;
|
const postId = req.params.id;
|
||||||
const post = await DB.getPost(postId);
|
const post = await DB.getPost(postId);
|
||||||
|
|||||||
Reference in New Issue
Block a user