Skip to main content
DELETE
/
api
/
time-blocks
/
:id
Delete Time Block
curl --request DELETE \
  --url https://api.example.com/api/time-blocks/:id
{
  "message": "<string>"
}
Delete a time block to remove doctor availability.

Authentication

Requires JWT authentication via Bearer token. Required Header:
Authorization: Bearer <token>

Authorization

Allowed roles:
  • doctor - Can delete their own time blocks only
  • admin - Can delete any time block

Path Parameters

id
integer
required
The unique identifier of the time block to deleteExample: 42

Response

message
string
Confirmation messageValue: "TimeBlock deleted successfully"

Error Responses

401 Unauthorized

Missing or invalid authentication token:
{
  "error": "Unauthorized"
}

403 Forbidden

Doctor attempting to delete another doctor’s time block:
{
  "error": "Access denied"
}

404 Not Found

Time block with specified ID does not exist:
{
  "error": "TimeBlock not found"
}

409 Conflict

Time block has an associated appointment (cannot delete):
{
  "error": "Cannot delete time block with existing appointment"
}

Example Request

curl -X DELETE https://api.example.com/api/time-blocks/42 \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Example Response

{
  "message": "TimeBlock deleted successfully"
}

Notes

  • Doctors can only delete their own time blocks
  • Admins can delete any time block
  • The database has an onDelete: Restrict constraint on appointments - time blocks with booked appointments cannot be deleted
  • To remove a time block with an appointment, the appointment must be cancelled/deleted first
  • Deletion is permanent and cannot be undone

Important Considerations

Database Constraints

The Appointment model has a foreign key constraint on timeBlockId with onDelete: Restrict. This means:
  • If a time block has an associated appointment, the deletion will fail
  • The appointment must be deleted first before the time block can be removed
  • This prevents orphaned appointments and maintains data integrity
  1. Check if time block has an appointment before attempting deletion
  2. If appointment exists, decide whether to:
    • Cancel/delete the appointment first, then delete the time block
    • Keep the time block and inform the user it cannot be deleted
  3. Only delete time blocks that are truly available (no appointments)

Alternative Approach

Consider implementing a “soft delete” or “disable” feature instead of permanent deletion for time blocks with appointments, allowing you to:
  • Mark time blocks as inactive/unavailable
  • Preserve historical appointment data
  • Maintain referential integrity

Build docs developers (and LLMs) love