new posts
This commit is contained in:
36
dbTools/post.js
Normal file
36
dbTools/post.js
Normal 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;
|
||||
Reference in New Issue
Block a user