Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions api/user/manageUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,25 @@ router.post('/setDisplayName/:id', (req, res) => {
});
});

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

const connection = await pool.promise().getConnection();
try {
await connection.beginTransaction();
await connection.query('DELETE FROM pending_requests WHERE user_id = ? OR friend_id = ?', [id, id]);
await connection.query('DELETE FROM friends_db WHERE user_id = ? OR friend_id = ?', [id, id]);
await connection.query('DELETE FROM live_status WHERE user_id = ?', [id]);
await connection.query('DELETE FROM users WHERE id = ?', [id]);
await connection.commit();
return res.status(200).json({ message: 'User data successfully deleted.' });
} catch (error) {
console.error(error);
await connection.rollback();
return res.status(500).json({ error: 'Error deleting user' });
} finally {
connection.release();
}
});

module.exports = router;