Overview
Deletes a role from the system. This is a soft delete operation that sets the role status to inactive rather than permanently removing it.
This endpoint requires administrator privileges (role_id: 1). Only admin users can delete roles.
Authentication
Required: Bearer token with admin privileges
Authorization: Bearer < admin_jwt_toke n >
Path Parameters
The unique identifier of the role to delete
Response
Indicates if the role was deleted successfully
Always null for delete operations
Examples
curl -X DELETE "http://localhost:4000/api/roles/3" \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
-H "Content-Type: application/json"
Response Examples
Success (200 OK)
{
"success" : true ,
"message" : "Role deleted successfully" ,
"data" : null
}
Unauthorized (401)
{
"success" : false ,
"message" : "Token no proporcionado o inválido"
}
Forbidden (403)
{
"success" : false ,
"message" : "Access denied. Admin privileges required"
}
Not Found (404)
{
"success" : false ,
"message" : "Role not found"
}
Error Responses
Status Code Description 400 Invalid role ID 401 Missing or invalid authentication token 403 User does not have admin privileges 404 Role not found 500 Internal server error
Soft Delete Behavior
This endpoint performs a soft delete by setting the role status to “inactive”. The role record remains in the database but is no longer active. This preserves referential integrity with users who may have this role assigned.
Important Notes
Deleting a role that is currently assigned to users may affect their permissions. Ensure you reassign affected users to a different role before deletion.
Create Role Create a new role
Update Role Modify role details
Source Code Reference
Route: src/routes/role.routes.js:delete
Controller: src/controllers/roleController.js:deleteRole