posting and commenting
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user