new posts

This commit is contained in:
Adolfo Reyna
2021-07-23 22:04:33 -07:00
parent 43df66efab
commit 6904ad913e
5 changed files with 117 additions and 7 deletions

36
dbTools/post.js Normal file
View File

@@ -0,0 +1,36 @@
const DBName = "EMI_SOCIAL";
const Post = require("./../def/post.js")
postDB = (DB)=>{
DB.postCols = DB.db.db(DBName).collection("posts");
DB.newPost = (postObj) => {
console.log(postObj)
return DB.postCols.insertOne(postObj.toObj()).catch((err)=>{
console.log(err);
return false;
});
}
DB.newComment = (postid, comment) => {
return DB.postCols.updateOne(postid, {
$push: {
comments: comment
},
$set: {
lastUpdated: new Date()
}
}).catch((err)=>{
console.log(err);
return false;
});
}
DB.getPosts = (userObj) => {
return DB.postCols.find().toArray().catch((err)=>{
console.log(err);
return false;
});
}
}
module.exports = postDB;