Files
EMI-Backend/dbTools/post.js
Adolfo Reyna 6904ad913e new posts
2021-07-23 22:04:33 -07:00

36 lines
877 B
JavaScript

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;