From 4349fa39b4e509550ca2253f16ec70115e92f4a9 Mon Sep 17 00:00:00 2001 From: Schneider Roland Date: Wed, 31 Dec 2025 12:27:25 +0100 Subject: [PATCH] feat: Add originalStartTime to event DTOs and service to correctly identify and manage event exceptions in the UI. --- ...le-event-dashboard-event-activation.component.ts | 13 +++++++++---- .../calendar/models/events-in-range-dto.model.ts | 3 ++- server/src/calendar/calendar.service.ts | 5 ++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/admin/src/app/features/calendar/components/calendar-view/single-event-dashboard-event-activation/single-event-dashboard-event-activation.component.ts b/admin/src/app/features/calendar/components/calendar-view/single-event-dashboard-event-activation/single-event-dashboard-event-activation.component.ts index f8fbc1c..9ca5e31 100644 --- a/admin/src/app/features/calendar/components/calendar-view/single-event-dashboard-event-activation/single-event-dashboard-event-activation.component.ts +++ b/admin/src/app/features/calendar/components/calendar-view/single-event-dashboard-event-activation/single-event-dashboard-event-activation.component.ts @@ -36,10 +36,15 @@ export class SingleEventDashboardEventActivation { const event = this.event(); console.info('setEventOccurrenceActivation', event); - const eventId = this.event()?.id!; - const startTime = this.event()?.startTime!; + const eventId = event?.id!; + const originalStartTime = event?.originalStartTime!; let payload: CreateExceptionDto | undefined; - const eventException = event?.exceptions?.length ? event.exceptions[0] : undefined; + + // Correctly find the exception that matches this specific occurrence + const eventException = event?.exceptions?.find(ex => + new Date(ex.originalStartTime).getTime() === new Date(originalStartTime).getTime() + ); + if (eventException) { payload = { ...eventException, @@ -50,7 +55,7 @@ export class SingleEventDashboardEventActivation { }; } else { payload = { - originalStartTime: new Date(startTime), + originalStartTime: new Date(originalStartTime), isCancelled: !activated, }; } diff --git a/admin/src/app/features/calendar/models/events-in-range-dto.model.ts b/admin/src/app/features/calendar/models/events-in-range-dto.model.ts index 46a032f..34a312a 100644 --- a/admin/src/app/features/calendar/models/events-in-range-dto.model.ts +++ b/admin/src/app/features/calendar/models/events-in-range-dto.model.ts @@ -16,7 +16,7 @@ export type BookingWithUserDto = { id: number; }; -export interface EventExceptionDto{ +export interface EventExceptionDto { id: number, description: string; eventId: number; @@ -33,6 +33,7 @@ export type CalendarEventDto = { id: number; title: string; startTime: string, + originalStartTime: string, endTime: string, description: string, isModified?: boolean; diff --git a/server/src/calendar/calendar.service.ts b/server/src/calendar/calendar.service.ts index e4e956f..3fe3c15 100644 --- a/server/src/calendar/calendar.service.ts +++ b/server/src/calendar/calendar.service.ts @@ -62,10 +62,10 @@ type BookingWithUserDto = { id: number; }; -// The final shape of a calendar event occurrence export type CalendarEventDto = Omit & { isModified?: boolean; isCancelled?: boolean; + originalStartTime: Date; eventBookings: BookingWithUserDto[]; }; @@ -146,6 +146,7 @@ export class CalendarService { const key = `${event.id}-${event.startTime.getTime()}`; return { ...event, + originalStartTime: event.startTime, eventBookings: bookingMap.get(key) || [], }; }); @@ -197,6 +198,7 @@ export class CalendarService { exception.newEndTime || new Date(occurrenceDate.getTime() + duration), isModified: true, + originalStartTime: occurrenceDate, eventBookings: bookingMap.get(key) || [], isCancelled: !!exception.isCancelled, }); @@ -206,6 +208,7 @@ export class CalendarService { recurringOccurrences.push({ ...event, startTime: occurrenceDate, + originalStartTime: occurrenceDate, endTime: new Date(occurrenceDate.getTime() + duration), eventBookings: bookingMap.get(key) || [], });