Overview
The Loan Request System enables administrators to review, approve, or reject book loan requests submitted by library users. The system tracks loan status through a state-based workflow (PENDIENTE → APROBADO/RECHAZADO) and manages book availability accordingly.When a loan is approved, the associated book’s availability is automatically updated to prevent duplicate loans.
Component Architecture
The loan management interface is implemented inPrestamoListComponent:
- TypeScript:
src/app/features/prestamos/prestamo-list/prestamo-list.ts:13 - Template:
src/app/features/prestamos/prestamo-list/prestamo-list.html - Service:
src/app/core/services/prestamo.ts:10
Dependencies
Admin Workflow
View Pending Requests
Access the loan management panel to see all loan requests sorted by ID (newest first)
Approve or Reject
For pending requests, click ”✅ Aprobar” to approve or ”❌ Rechazar” to deny the loan
Confirm Action
Confirm your decision in the dialog. The system updates the loan status and book availability
Core Functionality
Loading Loans
The component fetches all loans on initialization:prestamo-list.ts:17-28
Loans are sorted by ID in descending order to prioritize the newest requests at the top.
Approving Loans
Administrators can approve pending loan requests:prestamo-list.ts:30-39
Side Effects:
- Loan status changes from
PENDIENTEtoAPROBADO - Associated book’s
disponibleflag is set tofalse - Book becomes unavailable for new loan requests
Rejecting Loans
Administrators can reject loan requests:prestamo-list.ts:41-48
Side Effects:
- Loan status changes from
PENDIENTEtoRECHAZADO - Book remains available for other users
Service API
ThePrestamoService provides methods for all loan operations:
Available Methods
prestamo.ts:14-50
API Endpoints
POST /prestamos/solicitar/{libroId}
Submit a new loan request for a specific book (user action)
GET /prestamos/todos
Retrieve all loan requests (admin only)
GET /prestamos/mios
Retrieve loans for the authenticated user
POST /prestamos/aprobar/{id}
Approve a pending loan request (admin only)
POST /prestamos/rechazar/{id}
Reject a pending loan request (admin only)
UI Components
Loan Management Table
The interface displays loans in a structured table:prestamo-list.html:6-55
Status Badges
Loans display color-coded status badges:prestamo-list.html:24-35
- PENDIENTE: Yellow badge (requires admin action)
- APROBADO: Green badge (loan granted)
- RECHAZADO: Red badge (loan denied)
Conditional Actions
Action buttons only appear for pending loans:prestamo-list.html:38-51
Data Model
ThePrestamo model includes:
Loan States
The system uses three loan states:PENDIENTE
Initial state when a user submits a loan request. Awaiting admin review.
APROBADO
Admin has approved the request. Book is now unavailable for other users.
RECHAZADO
Admin has rejected the request. Book remains available.
Integration Points
With Book Catalog
When users browse the catalog (see Book Catalog), they can request loans via thesolicitarPrestamo() method, which calls:
catalogo.ts:45-54
With Book Management
When admins approve a loan, the backend automatically:- Updates the loan status to
APROBADO - Sets the book’s
disponiblefield tofalse - Prevents the book from appearing as available in the catalog
Features Summary
Request Queue
Centralized view of all loan requests sorted by recency
One-Click Approval
Quick approve/reject actions with confirmation dialogs
Status Tracking
Visual status indicators for pending, approved, and rejected loans
Automatic Updates
Book availability updates automatically when loans are approved
Related Features
- Book Catalog - User interface for browsing and requesting books
- Admin Panel - Manage books, authors, and genres