diff --git a/angular/RestClient/angular.json b/angular/RestClient/angular.json index 2755b4c5120ce49062c1503bef80d4591df7c653..b9017eb47cbc0d902128a7211d7d8f08c6d1f48a 100644 --- a/angular/RestClient/angular.json +++ b/angular/RestClient/angular.json @@ -102,5 +102,8 @@ } } } + }, + "cli": { + "analytics": false } } diff --git a/angular/RestClient/src/app/core/features/user/user-booking-list/user-booking-list.component.ts b/angular/RestClient/src/app/core/features/user/user-booking-list/user-booking-list.component.ts index 535ff5647ffc98db1b851a692c34cc80c0c3318d..5f1b3f1374342c3f9633486e6ce12027c2ebf7c5 100644 --- a/angular/RestClient/src/app/core/features/user/user-booking-list/user-booking-list.component.ts +++ b/angular/RestClient/src/app/core/features/user/user-booking-list/user-booking-list.component.ts @@ -79,10 +79,64 @@ export class UserBookingListComponent { this.bookingClient.deleteBooking(bookingId).subscribe({ next: () => { this.updateBookings(); + this.updateUserStatus(); }, error: (err) => { console.error('Error al eliminar una reserva', err); }, }); } + + updateUserStatus() { + this.client.getUserBookings(this.userId).subscribe({ + next: (bookings) => { + const withActive = bookings.find( + (booking) => this.genBookingState(booking) === 'Reserva activa' + ); + const withInactive = bookings.find( + (booking) => this.genBookingState(booking) === 'Reserva inactiva' + ); + if (withActive) { + this.client + .alterUserStatus(this.userId, 'WITH_ACTIVE_BOOKINGS') + .subscribe({ + next: (response) => { + console.log('Cambio de estado en el usuario a activo correcto'); + }, + error: (err) => { + console.error('Error al cambiar de estado al usuario a activo'); + }, + }); + } else if (withInactive) { + this.client + .alterUserStatus(this.userId, 'WITH_INACTIVE_BOOKINGS') + .subscribe({ + next: (response) => { + console.log( + 'Cambio de estado en el usuario a inactivo correcto' + ); + }, + error: (err) => { + console.error( + 'Error al cambiar de estado al usuario a inactivo' + ); + }, + }); + } else { + this.client.alterUserStatus(this.userId, 'NO_BOOKINGS').subscribe({ + next: (response) => { + console.log( + 'Cambio de estado en el usuario a sin reservas correcto' + ); + }, + error: (err) => { + console.error( + 'Error al cambiar de estado al usuario sin reservas' + ); + }, + }); + } + }, + }); + } } diff --git a/angular/RestClient/src/app/shared/booking.service.ts b/angular/RestClient/src/app/shared/booking.service.ts index 0800e99dc68cf58f01b93e5e54aca355cc552db1..535f4d55ae2c7492a18e0bbf8472c0e78ca99392 100644 --- a/angular/RestClient/src/app/shared/booking.service.ts +++ b/angular/RestClient/src/app/shared/booking.service.ts @@ -4,6 +4,7 @@ import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs'; import { Booking } from '../../types/Booking'; // Ajusta la ruta a tu modelo Booking +import { User, UserState } from '../../types'; @Injectable({ providedIn: 'root', // Esto hace que el servicio esté disponible en toda la aplicación