Skip to content

Commit 2025b86

Browse files
authored
Merge pull request #27 from Cattn/main
bring in changes from main
2 parents 872eb55 + d03b214 commit 2025b86

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

api/user/manageUser.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,25 @@ router.post('/setDisplayName/:id', (req, res) => {
123123
});
124124
});
125125

126+
router.delete('/delete/:id', async (req, res) => {
127+
const id = req.params.id;
128+
129+
const connection = await pool.promise().getConnection();
130+
try {
131+
await connection.beginTransaction();
132+
await connection.query('DELETE FROM pending_requests WHERE user_id = ? OR friend_id = ?', [id, id]);
133+
await connection.query('DELETE FROM friends_db WHERE user_id = ? OR friend_id = ?', [id, id]);
134+
await connection.query('DELETE FROM live_status WHERE user_id = ?', [id]);
135+
await connection.query('DELETE FROM users WHERE id = ?', [id]);
136+
await connection.commit();
137+
return res.status(200).json({ message: 'User data successfully deleted.' });
138+
} catch (error) {
139+
console.error(error);
140+
await connection.rollback();
141+
return res.status(500).json({ error: 'Error deleting user' });
142+
} finally {
143+
connection.release();
144+
}
145+
});
146+
126147
module.exports = router;

0 commit comments

Comments
 (0)