Delete profiles and posts

This commit is contained in:
aeroreyna
2022-02-16 20:33:20 -08:00
parent 294cacf963
commit 117bc5833a
5 changed files with 63 additions and 2 deletions

View File

@@ -9,7 +9,12 @@ DB.getDB.then((DB) => {
const getProfileId = (req) => {
return DB.ObjectID(req.cookies.profile_id || req.query.profile_id || req.body.profile_id);
}
};
const postBelongToProfile = (post, profileid) => {
if(!post) return false;
return post.profileid === profileid;
};
router.get("/", async (req, res) => {
const profileid = getProfileId(req);
@@ -144,6 +149,20 @@ DB.getDB.then((DB) => {
});
});
router.delete("/:id", async (req, res) => {
const profileid = getProfileId(req);
const postId = req.params.id;
const post = await DB.getPost(postId);
if(!postBelongToProfile(post, profileid))
return res.json({
status: "This post is not yours."
});
await DB.removePost(postId);
return res.json({
status: "ok"
});
});
});
module.exports = router