create booking
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -20,7 +20,7 @@ export class CalendarCreateBookingDto {
|
||||
@IsNotEmpty()
|
||||
@IsInt()
|
||||
@ApiProperty()
|
||||
userId: number; // Replaces userName/userEmail
|
||||
userId?: number; // Replaces userName/userEmail
|
||||
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
|
||||
Reference in New Issue
Block a user