posting and commenting

This commit is contained in:
Adolfo Reyna
2021-07-29 10:25:05 -07:00
parent 6904ad913e
commit 4069054117
4 changed files with 119 additions and 2 deletions

View File

@@ -11,8 +11,43 @@ postDB = (DB)=>{
});
}
DB.newReaction = (postid, userid, reaction) => {
const id = DB.ObjectID(postid);
let update = {
$set:{
reactions:{
[userid]: reaction
},
lastUpdated: new Date()
}
}
return DB.postCols.updateOne({_id: id}, update).catch((err)=>{
console.log(err);
return false;
});
}
DB.removeReaction = (postid, userid) => {
const id = DB.ObjectID(postid);
let update = {
$unset:{
reactions:{
[userid]: {}
}
},
$set: {
lastUpdated: new Date()
}
}
return DB.postCols.updateOne({_id: id}, update).catch((err)=>{
console.log(err);
return false;
});
}
DB.newComment = (postid, comment) => {
return DB.postCols.updateOne(postid, {
const id = DB.ObjectID(postid);
return DB.postCols.updateOne({_id: id}, {
$push: {
comments: comment
},
@@ -25,6 +60,25 @@ postDB = (DB)=>{
});
}
DB.newCommentReaction = (postid, commentDate, userid, reaction) => {
const id = DB.ObjectID(postid);
let update = {
$set:{
["comments.$.reactions." + userid]: reaction,
"comments.$.lastUpdated": new Date(),
lastUpdated: new Date()
}
}
console.log(JSON.stringify(update));
return DB.postCols.updateOne({
_id: id,
"comments.createdAt": commentDate
}, update).catch((err)=>{
console.log(err);
return false;
});
}
DB.getPosts = (userObj) => {
return DB.postCols.find().toArray().catch((err)=>{
console.log(err);