basic booking load behavior
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -152,4 +152,20 @@ export class CalendarService {
|
|||||||
|
|
||||||
return this.httpClient.patch(url, cancelBookingDto, requestOptions);
|
return this.httpClient.patch(url, cancelBookingDto, requestOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
calendarControllerGetBookings(eventId: number, startTime: Date, observe?: 'body', options?: RequestOptions<'json'>): Observable<any>;
|
||||||
|
calendarControllerGetBookings(eventId: number, startTime: Date, observe?: 'response', options?: RequestOptions<'json'>): Observable<HttpResponse<any>>;
|
||||||
|
calendarControllerGetBookings(eventId: number, startTime: Date, observe?: 'events', options?: RequestOptions<'json'>): Observable<HttpEvent<any>>;
|
||||||
|
calendarControllerGetBookings(eventId: number, startTime: Date, observe?: 'body' | 'events' | 'response', options?: RequestOptions<'arraybuffer' | 'blob' | 'json' | 'text'>): Observable<any> {
|
||||||
|
const url = `${this.basePath}/api/calendar/bookings/${eventId}/${startTime}`;
|
||||||
|
|
||||||
|
const requestOptions: any = {
|
||||||
|
observe: observe as any,
|
||||||
|
reportProgress: options?.reportProgress,
|
||||||
|
withCredentials: options?.withCredentials,
|
||||||
|
context: this.createContextWithClientId(options?.context)
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.httpClient.get(url, requestOptions);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
<h1>Foglalások</h1>
|
<h1>Foglalások</h1>
|
||||||
@for ( booking of bookings.value();track booking){
|
@if (bookings.isLoading()) {
|
||||||
|
<div>loading...</div>
|
||||||
|
} @else {
|
||||||
|
@for (booking of bookings.value()?.items; track booking) {
|
||||||
<div>
|
<div>
|
||||||
{{ booking }}
|
{{ booking }}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
<rs-daisy-pagination [pageCount]="pageCount()" [activePage]="1" (onPaginate)="paginate($event)"></rs-daisy-pagination>
|
<rs-daisy-pagination [pageCount]="pageCount()" [activePage]="activePage()" (onPaginate)="paginate($event)"></rs-daisy-pagination>
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { EventBusService } from '../../../../../services/event-bus.service';
|
|||||||
import { CalendarEventDto } from '../../../models/events-in-range-dto.model';
|
import { CalendarEventDto } from '../../../models/events-in-range-dto.model';
|
||||||
import { CalendarService } from '../../../../../../api';
|
import { CalendarService } from '../../../../../../api';
|
||||||
import { rxResource } from '@angular/core/rxjs-interop';
|
import { rxResource } from '@angular/core/rxjs-interop';
|
||||||
import { of } from 'rxjs';
|
import { delay, of } from 'rxjs';
|
||||||
import { Pagination } from '@rschneider/ng-daisyui';
|
import { Pagination } from '@rschneider/ng-daisyui';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -24,28 +24,32 @@ export class SingleEventBookingList {
|
|||||||
// bookings = toSignal(of(['a','b']));
|
// bookings = toSignal(of(['a','b']));
|
||||||
pageSize = input<number>(10);
|
pageSize = input<number>(10);
|
||||||
pageCount = computed(() => {
|
pageCount = computed(() => {
|
||||||
const bookings = this.bookings.value() ?? [];
|
return this.bookings.value()?.pageCount || 1;
|
||||||
let pageCount = Math.floor( bookings.length / this.pageSize());
|
|
||||||
if ( (bookings.length % this.pageSize()) > 0){
|
|
||||||
pageCount += 1;
|
|
||||||
}
|
|
||||||
pageCount = Math.max(pageCount ,1);
|
|
||||||
console.info("pageCount", pageCount);
|
|
||||||
return pageCount;
|
|
||||||
})
|
})
|
||||||
|
|
||||||
bookings = rxResource(
|
bookings = rxResource(
|
||||||
{
|
{
|
||||||
params: () => {
|
params: () => ({
|
||||||
page: this.activePage()
|
page: this.activePage()
|
||||||
},
|
}),
|
||||||
stream: ({params}) => {
|
stream: ({params}) => {
|
||||||
|
|
||||||
console.info("loading resource", params);
|
console.info("loading resource", params);
|
||||||
|
|
||||||
const allData = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t"]
|
const allData = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t"]
|
||||||
const pageData = allData.slice(this.activePage()-1,this.activePage()+this.pageSize())
|
|
||||||
|
let pageCount = Math.floor( allData.length / this.pageSize());
|
||||||
|
if ( (allData.length % this.pageSize()) > 0){
|
||||||
|
pageCount += 1;
|
||||||
|
}
|
||||||
|
pageCount = Math.max(pageCount ,1);
|
||||||
|
|
||||||
|
const pageData = allData.slice( ((this.activePage()-1) * this.pageSize()),this.activePage()*this.pageSize());
|
||||||
console.info("booking page data",pageData);
|
console.info("booking page data",pageData);
|
||||||
return of(pageData)
|
return of({
|
||||||
|
items: pageData,
|
||||||
|
pageCount
|
||||||
|
}).pipe( delay(1000))
|
||||||
},
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
ParseIntPipe,
|
ParseIntPipe,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
ValidationPipe,
|
ValidationPipe,
|
||||||
|
ParseDatePipe,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { CalendarService } from './calendar.service';
|
import { CalendarService } from './calendar.service';
|
||||||
import { GetCalendarDto } from './dto/get-calendar.dto';
|
import { GetCalendarDto } from './dto/get-calendar.dto';
|
||||||
@@ -99,4 +100,17 @@ export class CalendarController {
|
|||||||
) {
|
) {
|
||||||
return this.calendarService.cancelBooking(bookingId, cancelBookingDto);
|
return this.calendarService.cancelBooking(bookingId, cancelBookingDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('bookings/:eventId/:startTime')
|
||||||
|
getBookings(
|
||||||
|
@User() user: types.AppUser,
|
||||||
|
@Param('eventId', ParseIntPipe) eventId: number,
|
||||||
|
@Param('startTime', new ParseDatePipe()) startTime: Date,
|
||||||
|
) {
|
||||||
|
return this.calendarService.getBookings(
|
||||||
|
user.user!.userId,
|
||||||
|
eventId,
|
||||||
|
startTime,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -590,6 +590,31 @@ export class CalendarService {
|
|||||||
return this.bookingRepository.save(booking);
|
return this.bookingRepository.save(booking);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getBookings(
|
||||||
|
userId: number,
|
||||||
|
eventId: number,
|
||||||
|
startTime: Date,
|
||||||
|
): Promise<Booking[]> {
|
||||||
|
console.info('getBookings', userId, eventId, startTime);
|
||||||
|
await Promise.resolve();
|
||||||
|
// const booking = await this.bookingRepository.findOneBy({ id: bookingId });
|
||||||
|
// if (!booking) {
|
||||||
|
// throw new NotFoundException(`Booking with ID ${bookingId} not found.`);
|
||||||
|
// }
|
||||||
|
// if (booking.canceledAt) {
|
||||||
|
// throw new BadRequestException('This booking has already been cancelled.');
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Update the booking with cancellation details
|
||||||
|
// booking.canceledAt = new Date();
|
||||||
|
// booking.canceledReason = cancelBookingDto.canceledReason || null;
|
||||||
|
// booking.canceledByUserId = cancelBookingDto.canceledByUserId;
|
||||||
|
//
|
||||||
|
// return this.bookingRepository.save(booking);
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
private isValidOccurrence(event: Event, occurrenceTime: Date): boolean {
|
private isValidOccurrence(event: Event, occurrenceTime: Date): boolean {
|
||||||
console.info(
|
console.info(
|
||||||
'[CalendarService] isValidOccurrence called with event:',
|
'[CalendarService] isValidOccurrence called with event:',
|
||||||
|
|||||||
Reference in New Issue
Block a user