Overview
ThePrestamoService handles all operations related to book loans (préstamos) including requesting loans, listing loans, and managing loan approvals/rejections. It provides different methods for regular users and administrators.
Location: src/app/core/services/prestamo.ts
Constructor
inject() function to obtain HttpClient instance.
Properties
string
default:"${environment.apiUrl}/prestamos"
Base URL for prestamo endpoints, configured from environment settings.
Methods
solicitar()
Requests a loan for a specific book. Available to authenticated users.number
required
The unique identifier of the book to borrow
Observable<any> - Plain text response from server
Response Type: Text (uses responseType: 'text')
Example:
POST ${apiUrl}/solicitar/{libroId}
Request Body: Empty object {}
Use Case: When a user wants to borrow a book from the catalog
getAll()
Retrieves all loan requests from all users. Admin-only endpoint.Observable<Prestamo[]> - Array of all loan requests
array
Array of loan objects
number
Unique loan identifier
string
Date when the loan was requested (ISO 8601 format)
string
Date when the book was returned (if applicable)
string
Loan status: “PENDIENTE”, “APROBADO”, or “RECHAZADO”
Libro
Complete book object (id, titulo, portada, genero, autores, etc.)
any
User information from Spring Boot backend
GET ${apiUrl}/todos
Authorization: Requires ROLE_ADMIN
getMisPrestamos()
Retrieves loan requests for the currently authenticated user.Observable<Prestamo[]> - Array of current user’s loan requests
Example:
GET ${apiUrl}/mios
Authorization: Requires authentication (ROLE_USER or ROLE_ADMIN)
Use Case: Displaying user’s loan history and current requests
aprobar()
Approves a pending loan request. Admin-only operation.number
required
The unique identifier of the loan to approve
Observable<any> - Plain text response from server
Response Type: Text (uses responseType: 'text')
Example:
POST ${apiUrl}/aprobar/{id}
Request Body: Empty object {}
Authorization: Requires ROLE_ADMIN
Behavior: Changes loan status from PENDIENTE to APROBADO
rechazar()
Rejects a pending loan request. Admin-only operation.number
required
The unique identifier of the loan to reject
Observable<any> - Plain text response from server
Response Type: Text (uses responseType: 'text')
Example:
POST ${apiUrl}/rechazar/{id}
Request Body: Empty object {}
Authorization: Requires ROLE_ADMIN
Behavior: Changes loan status from PENDIENTE to RECHAZADO
Complete Usage Examples
User Component (Request and View Loans)
Admin Component (Manage All Loans)
Data Model
Prestamo Interface
Estado (Status) Values
string
Loan request is awaiting admin approval
string
Loan has been approved by an administrator
string
Loan has been rejected by an administrator
Error Handling
Common error scenarios:Authorization Requirements
See Also
- LibroService - Managing books available for loans
- AuthService - User authentication and roles
- Prestamo Model - Loan data structure