Skip to content

Commit

Permalink
[ADD] Delete user added
Browse files Browse the repository at this point in the history
  • Loading branch information
EliasJHL committed May 15, 2024
1 parent 3642880 commit cc7ee35
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/routes/user/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,33 @@ user_id.put("/", authenticateToken, (req, res) => {
};

db.query('UPDATE user SET ? WHERE id = ?', [user, id], (err, result) => {
if (err) {
if (err)
return res.status(500).json({msg: "Internal Server Error"});
}
return res.status(200).json({msg: "User updated !"});
});
});
});

user_id.delete("/", authenticateToken, (req, res) => {
const id = req.params.IDOrEmail;

if (!id) return res.status(400).json({msg: "Bad parameter"});
if (isNaN(id)) return res.status(400).json({msg: "Bad parameter"});

db.query('DELETE FROM user WHERE id = ?', [id], (err, result) => {
if (err)
return res.status(500).json({msg: "Internal Server Error"});
return res.status(200).json({msg: `Successfully deleted record number : ${id}`});
});
});

user_todos.get("/", authenticateToken, (req, res) => {
const id = req.user.id;

if (!id) return res.status(500).json({msg: "Internal Server Error"});
db.query('SELECT * FROM todo WHERE user_id = ?', [id], (err, result) => {
if (err) {
if (err)
return res.status(500).json({msg: "Internal Server Error"});
}
if (result.length <= 0) return res.status(404).json({msg: "Not Found"})
return res.status(200).json(result);
});
Expand Down

0 comments on commit cc7ee35

Please sign in to comment.