Skip to main content

Overview

The PrestamoListComponent provides administrators with a view of all loan requests in the system. Admins can approve or reject pending loan requests, and view the history of all loans.

Component Metadata

Selector: app-prestamo-list Imports:
  • CommonModule - Angular common directives
Template: ./prestamo-list.html

Properties

prestamos

Array containing all loan requests in the system. Each Prestamo object includes:
  • id: Loan request identifier
  • libro: Book object with title and details
  • usuario: User who requested the loan
  • fechaSolicitud: Date when the loan was requested
  • estado: Loan status (PENDIENTE, APROBADO, RECHAZADO)
The array is sorted by ID in descending order (newest first) with pending requests prioritized.

Injected Services

  • PrestamoService - Handles all loan-related API operations

Lifecycle Hooks

ngOnInit

Called when the component initializes. Immediately loads all loan requests from the backend.

Methods

cargarPrestamos

Fetches all loan requests from the PrestamoService:
  • Calls PrestamoService.getAll()
  • Sorts the results by ID in descending order (newest first)
  • Populates the prestamos array
This method is called on initialization and after approving or rejecting a loan to refresh the list.

aprobar

Approves a pending loan request:
  1. Displays confirmation dialog “¿Aprobar este préstamo? El libro dejará de estar disponible.”
  2. If confirmed, calls PrestamoService.aprobar() with the loan ID
  3. On success:
    • Shows alert “Préstamo Aprobado”
    • Reloads the loan list by calling cargarPrestamos()
When a loan is approved, the associated book’s disponible status is set to false by the backend. Parameters:
  • id - The numeric ID of the loan request to approve

rechazar

Rejects a pending loan request:
  1. Displays confirmation dialog “¿Rechazar solicitud?”
  2. If confirmed, calls PrestamoService.rechazar() with the loan ID
  3. On success:
    • Shows alert “Solicitud Rechazada”
    • Reloads the loan list by calling cargarPrestamos()
Rejecting a loan does not affect the book’s availability status. Parameters:
  • id - The numeric ID of the loan request to reject

Full Source Code

  • Prestamo - Loan request data structure
  • Libro - Book data structure