Update an existing time block’s start and/or end time.
Authentication
Requires JWT authentication via Bearer token.
Required Header:
Authorization: Bearer <token>
Authorization
Allowed roles:
doctor - Can update their own time blocks only
admin - Can update any time block
Path Parameters
The unique identifier of the time block to updateExample: 42
Request Body
At least one field must be provided.
The ID of the doctor (admin-only field for ownership verification)
- Optional for ADMIN role - Positive integer
- Forbidden for DOCTOR role - Automatically set to authenticated doctor’s ID for validation
New start time of the availability block in ISO 8601 formatFormat: YYYY-MM-DDTHH:mm:ss.sssZExample: 2026-03-15T09:30:00.000Z
New end time of the availability block in ISO 8601 formatFormat: YYYY-MM-DDTHH:mm:ss.sssZValidation: Must be greater than startTime (if both are provided)Example: 2026-03-15T10:30:00.000Z
Response
Unique identifier for the time block
ID of the doctor who owns this time block
Updated start time in ISO 8601 format
Updated end time in ISO 8601 format
Original creation date/timestamp
Record creation timestamp
Last update timestamp (reflects this update)
Error Responses
400 Bad Request
Validation errors:
{
"error": "Validation failed",
"details": [
"At least one field must be provided",
"endTime must be greater than startTime"
]
}
401 Unauthorized
Missing or invalid authentication token:
{
"error": "Unauthorized"
}
403 Forbidden
Doctor attempting to update 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
Update would create a duplicate time block:
{
"error": "Time block with these times already exists"
}
Example Request
Update Start Time Only
curl -X PUT https://api.example.com/api/time-blocks/42 \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"startTime": "2026-03-15T09:30:00.000Z"
}'
Update Both Times
curl -X PUT https://api.example.com/api/time-blocks/42 \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"startTime": "2026-03-15T09:30:00.000Z",
"endTime": "2026-03-15T10:30:00.000Z"
}'
Example Response
{
"id": 42,
"doctorId": 5,
"startTime": "2026-03-15T09:30:00.000Z",
"endTime": "2026-03-15T10:30:00.000Z",
"date": "2026-03-03T10:30:00.000Z",
"createdAt": "2026-03-03T10:30:00.000Z",
"updatedAt": "2026-03-03T11:45:00.000Z"
}
Notes
- Doctors are automatically restricted to updating only their own time blocks
- The
doctorId field in request body is used for ownership validation (set automatically for doctors)
- At least one field (
startTime or endTime) must be provided in the update
- The database unique constraint on
(doctorId, startTime, endTime) still applies
- Time blocks that are already booked (have an appointment) can still be updated, but consider business logic implications