diff --git a/src/server.js b/src/server.js index 0204714..7bbd208 100644 --- a/src/server.js +++ b/src/server.js @@ -323,6 +323,7 @@ app.post("/submit_post", (req,res) => { else if (users[func.get_userID(username)]['hash'] == password) { // Password matches console.log(username, "is submitting a post titled:", title); posts.push({ + "id": posts.length, "userID": func.get_userID(username), "title": title, "content": content, @@ -354,6 +355,7 @@ app.post("/submit_signup", (req,res) => { // so this checks that the user does not exist if (func.get_userID(username) == -1) { users.push({ + "id": users.length, "username": username, "prettyname": prettyname, "hash": password, @@ -398,12 +400,12 @@ app.post("/submit_edit_user", (req,res) => { if (delete_bool == true) { // Delete the user - users[userID] = {"deleted": true} + users[userID] = {"id": userID,"deleted": true} // Delete all their posts for (let postid = 0; postid < posts.length; postid++) { // loop over all posts if (posts[postid]['userID'] == userID) { // if userID matches - posts[postid] = {"deleted": true} // delete the post - comments.comments[postid] = {"deleted": true} // the comments for this post should also be deleted + posts[postid] = {"id": postid, "deleted": true} // delete the post + comments.comments[postid] = [] // the comments for this post should also be deleted } }; } @@ -447,8 +449,8 @@ app.post("/submit_edit_post", (req,res) => { post['editdate'] = unix_timestamp if (typeof delete_bool != "undefined") { console.log("Deleting post!") - posts[postID] = {"deleted": true} - comments.comments[postID] = {"deleted": true} + posts[postID] = {"id": post["id"], "deleted": true} + comments.comments[postID] = []; fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8'); } fs.writeFileSync(`../data/posts.json`, `${JSON.stringify(posts)}`, 'utf-8');