add update post endpoint
This commit is contained in:
@@ -19,6 +19,23 @@ postDB = (DB)=>{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DB.updatePost = (postid, newContent, oldContent) => {
|
||||||
|
const id = DB.ObjectID(postid);
|
||||||
|
let update = {
|
||||||
|
$set:{
|
||||||
|
content: newContent,
|
||||||
|
// lastUpdated: new Date() // add back when finish updating videos.
|
||||||
|
},
|
||||||
|
$push: {
|
||||||
|
contentHistory: oldContent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DB.postCols.updateOne({_id: id}, update).catch((err)=>{
|
||||||
|
console.log(err);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
DB.newReaction = (postid, profileid, reaction) => {
|
DB.newReaction = (postid, profileid, reaction) => {
|
||||||
const id = DB.ObjectID(postid);
|
const id = DB.ObjectID(postid);
|
||||||
let update = {
|
let update = {
|
||||||
|
|||||||
@@ -240,6 +240,21 @@ DB.getDB.then((DB) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.post("/:id", async (req, res) => {
|
||||||
|
const profileid = getProfileId(req) + '';
|
||||||
|
const postId = req.params.id;
|
||||||
|
const post = await DB.getPost(postId);
|
||||||
|
const newContent = req.body.content;
|
||||||
|
if (!postBelongToProfile(post, profileid))
|
||||||
|
return res.json({
|
||||||
|
status: "This post is not yours."
|
||||||
|
});
|
||||||
|
await DB.updatePost(postId, newContent, post.content);
|
||||||
|
return res.json({
|
||||||
|
status: "ok"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router
|
||||||
Reference in New Issue
Block a user