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

some details in hotel html and angular files

parent 3bc78e90
No related branches found
No related tags found
2 merge requests!10Add ts types and json mocks, remove poblate scripts and fix the cascade...,!7Dev/angular/hotel register
......@@ -47,7 +47,6 @@ export class HotelListComponent {
getHotels() {
this.client.getAllHotels().subscribe({
next: (resp) => {
console.warn({ resp });
if (!!resp || (resp as never[]).length != 0) this.hotels = [...resp];
},
error(err) {
......@@ -59,8 +58,6 @@ export class HotelListComponent {
deleteHotel(id: number) {
if (!confirm(`Borrar hotel con id ${id}. Continuar?`)) return;
// this.hotels = this.hotels.filter((h) => h.id !== id);
// return;
this.client.deleteHotel(id).subscribe({
next: (resp) => {
......@@ -85,16 +82,6 @@ export class HotelListComponent {
roomId: number,
availability: boolean
) {
// const target = hotels
// .find((hotel) => hotel.id === hotelId)!
// .rooms.find((room) => room.id === roomId);
// if (!target) {
// alert('Error');
// return;
// }
// const availability = !target.available;
// target.available = availability;
// alert(`Change availability from room ${roomId} to ${availability}`);
this.client.alterRoomAvailability(hotelId, roomId, availability).subscribe({
next: (resp) => {
if (resp.status < 400) {
......
......
......@@ -6,7 +6,7 @@
>
<mat-card-content>
<div class="form-group">
<label for="name" class="fs-2">Nombre del Hotel</label>
<label for="name" class="display-2">Nombre del Hotel</label>
<input
id="name"
class="form-control fs-3"
......@@ -56,6 +56,7 @@
class="btn btn-primary rounded-circle"
(click)="addRoom()"
[hidden]="editMode"
[disabled]="editMode"
>
<strong class="fs-2">+</strong>
</button>
......@@ -81,6 +82,7 @@
(click)="removeRoom(i)"
[disabled]="rooms.length <= 1"
[hidden]="editMode"
[disabled]="editMode"
>
Eliminar
</button>
......@@ -123,7 +125,8 @@
type="submit"
class="btn btn-success"
(click)="onSubmit()"
[disabled]="!hotelForm.valid"
[disabled]="editMode || !hotelForm.valid"
[hidden]="editMode"
>
<h4>Guardar Hotel</h4>
</button>
......
......
import { Component } from '@angular/core';
import {
AbstractControl,
FormArray,
FormBuilder,
FormGroup,
......@@ -18,17 +17,16 @@ import { ClienteApiRestService } from '../shared/cliente-api-rest.service';
import { Address, Hotel, Room } from '../../types';
import { ActivatedRoute, Router } from '@angular/router';
const emptyHotel: Hotel = {
id: 0,
name: '',
rooms: [
{
const emptyRoom: Room = {
id: 0,
available: false,
roomNumber: '',
type: 'SINGLE',
},
],
available: false,
};
const emptyHotel: Hotel = {
id: 0,
name: '',
rooms: [emptyRoom],
address: {
id: 0,
number: 0,
......@@ -73,11 +71,10 @@ export class HotelRegisterComponent {
this.client.getHotel(id).subscribe({
next: (h) => this.setHotelForm(h),
error: (error) => {
router.navigate(['/hotels/new']);
this.router.navigate(['/hotels/new']);
},
});
}
console.warn({ id });
},
});
}
......@@ -89,16 +86,15 @@ export class HotelRegisterComponent {
// Agregar una nueva habitación
addRoom(): void {
const roomForm = this.fb.group({
roomNumber: ['', Validators.required],
type: ['SINGLE', Validators.required],
available: [true],
roomNumber: [emptyRoom.roomNumber, Validators.required],
type: [emptyRoom.type, Validators.required],
available: [emptyRoom.available],
});
this.rooms.push(roomForm);
}
// Eliminar habitación
removeRoom(index: number): void {
alert('remove action');
this.rooms.removeAt(index);
}
......@@ -106,11 +102,11 @@ export class HotelRegisterComponent {
onSubmit(): void {
if (this.hotelForm.valid) {
const hotel = this.hotelForm.value as Hotel;
console.log(hotel);
this.client.addHotel(hotel).subscribe({
next: (resp) => {
if (resp.status < 400) {
alert('Hotel guardado correctamente');
this.router.navigate(['/hotels']);
} else {
}
},
......@@ -146,7 +142,7 @@ export class HotelRegisterComponent {
this.fb.group({
roomNumber: [room.roomNumber, Validators.required],
type: [room.type, Validators.required],
available: [true],
available: [room.available],
}),
Validators.required
)
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment