diff --git a/angular/RestClient/src/app/core/services/api/hotels/hotel-client.service.ts b/angular/RestClient/src/app/core/services/api/hotels/hotel-client.service.ts index 662ebd07f1bef996d298bf370be0e9095ac57f1c..3a3fe7b0883978b2228dbad54895fca2c0f3f3ef 100644 --- a/angular/RestClient/src/app/core/services/api/hotels/hotel-client.service.ts +++ b/angular/RestClient/src/app/core/services/api/hotels/hotel-client.service.ts @@ -5,7 +5,6 @@ import { SessionService } from '../../session/session.service'; import { catchError, map, switchMap, throwError } from 'rxjs'; import { Hotel, Room } from '@features/hotels'; - @Injectable({ providedIn: 'root', }) @@ -21,13 +20,12 @@ export class HotelClientService { return this.http.get<Hotel>(url); } - getAllHotels(startDate?: Date, endDate?: Date) { + getAllHotels(start?: string, end?: string) { const url = `${this.URI}`; - if (!startDate || !endDate) return this.http.get<Hotel[]>(url); - const start = new Date(startDate).toISOString().split('T')[0]; - const end = new Date(endDate).toISOString().split('T')[0]; - console.log({start, end}) - + console.log({ start, end }); + + if (!start || !end) return this.http.get<Hotel[]>(url); + return this.http.get<Hotel[]>(url, { params: { start, end } }); } diff --git a/angular/RestClient/src/app/features/hotels/hotel-list/hotel-list.component.ts b/angular/RestClient/src/app/features/hotels/hotel-list/hotel-list.component.ts index 2ae04a93f7b2cab834214fbff80efb7de43623a1..88af410e734454e71e2cf70f02f84b63a845e016 100644 --- a/angular/RestClient/src/app/features/hotels/hotel-list/hotel-list.component.ts +++ b/angular/RestClient/src/app/features/hotels/hotel-list/hotel-list.component.ts @@ -68,8 +68,7 @@ export class HotelListComponent { rooms: Room[] = []; trateRooms: Room[] = []; userId = 0; - start:Date = new Date(new Date().getDate() - 3); - end:Date = new Date(new Date().getDate() - 3); + end = ''; constructor( private fb: FormBuilder, @@ -109,8 +108,8 @@ export class HotelListComponent { ngOnInit(): void { this.getHotels(); - this.dateRangeForm.get('dateRange')?.valueChanges.subscribe(() => { - this.getHotels(); + this.dateRangeForm.get('dateRange')?.valueChanges.subscribe((value) => { + this.getHotels(value); }); } @@ -152,21 +151,33 @@ export class HotelListComponent { return value; } - getHotels() { - const { start, end } = this.dateRangeForm.value.dateRange; - console.log({start, end, s:this.start, e:this.end}) - if (end != null && this.end.getDate() === end.getDate()) return + getDate(date: Date) { + return date.toISOString().split('T')[0]; + } + + getHotels(value?: { end: Date; start: Date }) { + const { start: startDate, end: endDate } = + value ?? this.dateRangeForm.value.dateRange; + + if (!endDate) return; + + const start = this.getDate(startDate); + const end = this.getDate(endDate); + + if (this.end != null && this.end === end) { + console.log('SKIP'); + return; + } - const observable = this.isManaging - ? this.hotelClient.getAllHotelsByUser(this.userId) - : this.hotelClient.getAllHotels(start, end); - + ? this.hotelClient.getAllHotelsByUser(this.userId) + : this.hotelClient.getAllHotels(start, end); + observable.subscribe({ next: (resp) => { + console.log(this.isManaging, resp); if (!!resp && (resp as never[]).length >= 0) { - this.start = start - this.end = end + this.end = end; this._hotels = resp; this.update(); }