Skip to content
Snippets Groups Projects
Commit 41ec7afe authored by migudel's avatar migudel :speech_balloon:
Browse files

user status update after booking delete

parent a7131719
No related branches found
No related tags found
1 merge request!10Add ts types and json mocks, remove poblate scripts and fix the cascade...
......@@ -102,5 +102,8 @@
}
}
}
},
"cli": {
"analytics": false
}
}
......@@ -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'
);
},
});
}
},
});
}
}
......@@ -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
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment