Reservations Endpoints
API reference for book reservation operations — create, cancel, fulfill, and list reservations.
Reservations Endpoints
Manage book hold requests. Students and staff can create and cancel their own reservations; librarians and admins can view all reservations and fulfill them.
Base Path: /api/v1/reservations
All endpoints require authentication (authenticate middleware applied globally on the router).
Create Reservation
POST /api/v1/reservationsReserves an available copy of the specified book for the authenticated user. The copy's status is set to RESERVED and a 48-hour expiry window is created.
Authorization: Any authenticated user
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
bookId | String (ObjectId) | ✅ | The ID of the book to reserve |
Success Response — 201 Created
{
"reservation": {
"_id": "...",
"userId": "...",
"bookCopyId": "...",
"expiresAt": "2026-07-08T21:00:00.000Z",
"status": "PENDING",
"reservedAt": "2026-07-06T21:00:00.000Z"
},
"message": "Book reserved successfully"
}Error Responses
| Code | Condition |
|---|---|
400 | No available copies for the specified book |
401 | Not authenticated |
500 | Internal server error |
Business Logic
- Finds the first
BookCopywithstatus: AVAILABLEfor the givenbookId - Sets the copy status to
RESERVED - Creates a
Reservationrecord with a 48-hourexpiresAttimestamp - Returns the reservation object
Cancel Reservation
POST /api/v1/reservations/:id/cancelCancels a pending reservation owned by the authenticated user. Releases the reserved copy back to AVAILABLE status.
Authorization: Any authenticated user (own reservations only)
Path Parameters
| Parameter | Description |
|---|---|
id | Reservation ID |
Success Response — 200 OK
{
"message": "Reservation cancelled successfully"
}Error Responses
| Code | Condition |
|---|---|
400 | Reservation not found, not owned by user, or already processed |
401 | Not authenticated |
500 | Internal server error |
Fulfill Reservation
POST /api/v1/reservations/:id/fulfillConverts a pending reservation into an active loan. This is a librarian/admin desk operation performed when the patron picks up the reserved book.
Authorization: ROLE_ADMIN, ROLE_LIBRARIAN
Path Parameters
| Parameter | Description |
|---|---|
id | Reservation ID |
Success Response — 200 OK
{
"message": "Reservation fulfilled and book checked out",
"transaction": {
"_id": "...",
"userId": "...",
"bookCopyId": "...",
"issuedAt": "2026-07-06T21:00:00.000Z",
"dueDate": "2026-07-20T21:00:00.000Z",
"renewalCount": 0
}
}Business Logic
- Validates reservation exists and has
PENDINGstatus - Sets reservation status to
FULFILLED - Sets the book copy status to
CHECKED_OUT - Creates a
Transaction(loan) with a 14-day due date - Sends a
SUCCESSnotification to the user: "Your reserved book has been successfully picked up"
Error Responses
| Code | Condition |
|---|---|
400 | Reservation not found or not in PENDING state |
403 | Insufficient privileges |
500 | Internal server error |
List My Reservations
GET /api/v1/reservations/meReturns all reservations belonging to the authenticated user, sorted by newest first. Includes populated book copy and book details.
Authorization: Any authenticated user
Success Response — 200 OK
{
"reservations": [
{
"_id": "...",
"userId": "...",
"bookCopyId": {
"_id": "...",
"barcode": "BC-0001",
"status": "RESERVED",
"bookId": {
"_id": "...",
"title": "Introduction to Algorithms",
"author": "Thomas Cormen"
}
},
"status": "PENDING",
"expiresAt": "2026-07-08T21:00:00.000Z",
"reservedAt": "2026-07-06T21:00:00.000Z"
}
]
}List All Reservations
GET /api/v1/reservationsReturns all reservations across all users. Includes populated user info and book details.
Authorization: ROLE_ADMIN, ROLE_LIBRARIAN
Success Response — 200 OK
{
"reservations": [
{
"_id": "...",
"userId": {
"firstName": "John",
"lastName": "Doe",
"email": "john@example.com",
"rollNumber": "CS2024001"
},
"bookCopyId": {
"barcode": "BC-0001",
"bookId": {
"title": "Introduction to Algorithms"
}
},
"status": "PENDING",
"expiresAt": "...",
"reservedAt": "..."
}
]
}Route Summary
| Method | Path | Auth | Description |
|---|---|---|---|
POST | /reservations | ✅ | Create reservation |
GET | /reservations/me | ✅ | List own reservations |
POST | /reservations/:id/cancel | ✅ | Cancel own reservation |
GET | /reservations | Admin, Librarian | List all reservations |
POST | /reservations/:id/fulfill | Admin, Librarian | Fulfill reservation into loan |