From a5691d94679380736ace5199f21c1abd5fd3c574 Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 22 Jan 2023 15:47:22 -0500 Subject: [PATCH 1/2] delete user works --- backend/routes/users.js | 5 ++--- client/src/views/ValidatedUsers.jsx | 26 ++++++++++---------------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/backend/routes/users.js b/backend/routes/users.js index a4fe0b807..bc544f994 100644 --- a/backend/routes/users.js +++ b/backend/routes/users.js @@ -37,9 +37,8 @@ router.get("/", async (req, res) => { router.delete("/:id", async (req, res) => { try { const { id } = req.params; - console.log(id); - // does not work, come back to this - res.send("Got a DELETE request at /user"); + await User.deleteOne({ _id: id }); + res.send("Got a DELETE request at /users"); } catch (error) { console.log(error); } diff --git a/client/src/views/ValidatedUsers.jsx b/client/src/views/ValidatedUsers.jsx index 805185a1c..60ee1519e 100644 --- a/client/src/views/ValidatedUsers.jsx +++ b/client/src/views/ValidatedUsers.jsx @@ -8,7 +8,7 @@ export default class ValidatedUsers extends React.Component { users: [], }; - componentDidMount() { + async getValidatedUsers() { const url = "/api/users"; axios.get(url).then((res) => { const users = res.data; @@ -16,24 +16,18 @@ export default class ValidatedUsers extends React.Component { }); } - deleteUser(user) { + componentDidMount() { + this.getValidatedUsers(); + } + + async deleteUser(user) { const id = user._id; console.log(id); const url = "/api/users/" + id; - const res = axios.delete(url).then((res) => { - console.log(res); - // this.setState({ - // users: this.state.users.slice( - // this.state.users.indexOf((user) => { - // return user._id === id; - // }), - // 1 - // ), - // }); - // FIX THIS - //window.location.reload(); - }); - console.log(res); + console.log(url); + await axios.delete(url).then(() => { + window.location.reload(); + }).catch((error) => console.log("Error: ", error)); } // functionality for ensuring unauthenticated users cannot view From 7cc0e8fc7c8fd9f9d243e998d99ea9b70e70f078 Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 22 Jan 2023 15:49:12 -0500 Subject: [PATCH 2/2] dropped rando console logs --- client/src/views/ValidatedUsers.jsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/client/src/views/ValidatedUsers.jsx b/client/src/views/ValidatedUsers.jsx index 60ee1519e..a78803a21 100644 --- a/client/src/views/ValidatedUsers.jsx +++ b/client/src/views/ValidatedUsers.jsx @@ -22,9 +22,7 @@ export default class ValidatedUsers extends React.Component { async deleteUser(user) { const id = user._id; - console.log(id); const url = "/api/users/" + id; - console.log(url); await axios.delete(url).then(() => { window.location.reload(); }).catch((error) => console.log("Error: ", error));