Skip to content

Commit

Permalink
Merge pull request #14 from RbAvci/RbAvci/-Backend]-Implement-API-for…
Browse files Browse the repository at this point in the history
…-delete-a-user-account

#13-Implement API for delete a user account-RabiaAvci
  • Loading branch information
RbAvci authored Jul 18, 2024
2 parents b67389c + bc60e32 commit bd9da7a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions server/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,30 @@ router.post("/users", async (req, res) => {
});


router.delete("/users/:id", async (req, res) => {
const userId = req.params.id;

try {
const result = await db.query(
"DELETE FROM users WHERE id = $1 RETURNING id",
[userId]
);

if (result.rows.length === 0) {
return res
.status(404)
.json({ success: false, message: "User not found" });
}

res.status(200).json({ success: true, data: { id: result.rows[0].id } });
} catch (error) {
res
.status(500)
.json({
success: false,
error: "Failed to delete User from the database",
});
}
});

export default router;

0 comments on commit bd9da7a

Please sign in to comment.