create booking

This commit is contained in:
Schneider Roland
2025-12-14 22:11:42 +01:00
parent e86b356baf
commit 056b9f6c80
35 changed files with 2496 additions and 14 deletions

View File

@@ -84,7 +84,11 @@ export class CalendarController {
@Body(new ValidationPipe()) createBookingDto: CalendarCreateBookingDto,
) {
console.info('user user', user);
return this.calendarService.createBooking(eventId, createBookingDto);
return this.calendarService.createBooking(
user.user!.userId,
eventId,
createBookingDto,
);
}
// Cancel a specific booking (soft delete)

View File

@@ -519,12 +519,18 @@ export class CalendarService {
}
async createBooking(
userId: number,
eventId: number,
createBookingDto: CalendarCreateBookingDto,
): Promise<Booking> {
const { occurrenceStartTime, userId } = createBookingDto;
const { occurrenceStartTime } = createBookingDto;
const event = await this.eventRepository.findOneBy({ id: eventId });
const event = await this.eventRepository.findOne({
where: {
id: eventId,
},
relations: ['bookings', 'exceptions', 'recurrenceRule'],
});
if (!event)
throw new NotFoundException(`Event with ID ${eventId} not found.`);
@@ -585,8 +591,14 @@ export class CalendarService {
}
private isValidOccurrence(event: Event, occurrenceTime: Date): boolean {
console.info(
'[CalendarService] isValidOccurrence called with event:',
event,
'occurrenceTime',
occurrenceTime,
);
// Check if the occurrence has been explicitly cancelled
const exception = event.exceptions.find(
const exception = (event?.exceptions ?? []).find(
(ex) => ex.originalStartTime.getTime() === occurrenceTime.getTime(),
);
if (exception && exception.isCancelled) {

View File

@@ -20,7 +20,7 @@ export class CalendarCreateBookingDto {
@IsNotEmpty()
@IsInt()
@ApiProperty()
userId: number; // Replaces userName/userEmail
userId?: number; // Replaces userName/userEmail
@IsOptional()
@IsInt()