dev #2961
Updated by Zahid Hassan 8 months ago
## Summary
This feature enhances the **user management system** with safer deletion workflows, and bulk operations. It introduces improves query safety by using Drizzle helpers, and adds comprehensive bulk deletion support for admins. The changes also strengthen error handling and ensure safe deletion processes with database transactions.
## Changes
### 2. Delete API Enhancements
- **Admin Delete Updates**
- Accept userIds as a comma-separated string for bulk processing.
- Generate `toolActions` objects for all tools owned by the selected users.
### 3. Bulk Delete Functionality
- **New Features**
- Implemented **bulk delete** for admins, allowing multiple users to be deleted at once.
- Updated `status` and `verificationMethod` in the `toolVerifications` table so tools can be reclaimed by new owners later.
- **Transaction Safety**
- Used database transactions for user deletions (both admin and non-admin) to ensure safe, atomic operations.
### 4. Error Handling
- **Error Context**
- Updated `errorHandler` for `FORBIDDEN` errors to include detailed error context.
### Example Usage
#### Bulk Delete for Admin
**Request Body**
```javascript
{
"userIdsToDelete":"47,45"
}
```
**Expected Response**
```javascript
{
"success": true,
"message": "Users deleted successfully",
"usersDeleted": [
"47",
"45"
]
}
```
#### Normal Delete for Non-Admin
**Request Body**
```javascript
{
"toolActions": [
{ "toolId": "f13ae2e9-5f6c-4d65-835c-958fb7ecf746", "action": "delete" },
{ "toolId": "c6869a87-09eb-450a-b7fb-f2ac8961c6cf", "action": "transfer", "newOwnerId": 2 }
]
}
```
**Expected Response**
```javascript
{
"success": true,
"message": "Users deleted successfully",
"usersDeleted": [
"57"
]
}
```