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

fix hotel search

parent c841e966
No related branches found
No related tags found
1 merge request!36Develop
......@@ -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 } });
}
......
......@@ -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();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment