feat: Add originalStartTime to event DTOs and service to correctly identify and manage event exceptions in the UI.
This commit is contained in:
@@ -36,10 +36,15 @@ export class SingleEventDashboardEventActivation {
|
|||||||
|
|
||||||
const event = this.event();
|
const event = this.event();
|
||||||
console.info('setEventOccurrenceActivation', event);
|
console.info('setEventOccurrenceActivation', event);
|
||||||
const eventId = this.event()?.id!;
|
const eventId = event?.id!;
|
||||||
const startTime = this.event()?.startTime!;
|
const originalStartTime = event?.originalStartTime!;
|
||||||
let payload: CreateExceptionDto | undefined;
|
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) {
|
if (eventException) {
|
||||||
payload = {
|
payload = {
|
||||||
...eventException,
|
...eventException,
|
||||||
@@ -50,7 +55,7 @@ export class SingleEventDashboardEventActivation {
|
|||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
payload = {
|
payload = {
|
||||||
originalStartTime: new Date(startTime),
|
originalStartTime: new Date(originalStartTime),
|
||||||
isCancelled: !activated,
|
isCancelled: !activated,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export type BookingWithUserDto = {
|
|||||||
id: number;
|
id: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface EventExceptionDto{
|
export interface EventExceptionDto {
|
||||||
id: number,
|
id: number,
|
||||||
description: string;
|
description: string;
|
||||||
eventId: number;
|
eventId: number;
|
||||||
@@ -33,6 +33,7 @@ export type CalendarEventDto = {
|
|||||||
id: number;
|
id: number;
|
||||||
title: string;
|
title: string;
|
||||||
startTime: string,
|
startTime: string,
|
||||||
|
originalStartTime: string,
|
||||||
endTime: string,
|
endTime: string,
|
||||||
description: string,
|
description: string,
|
||||||
isModified?: boolean;
|
isModified?: boolean;
|
||||||
|
|||||||
@@ -62,10 +62,10 @@ type BookingWithUserDto = {
|
|||||||
id: number;
|
id: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
// The final shape of a calendar event occurrence
|
|
||||||
export type CalendarEventDto = Omit<Event, 'bookings'> & {
|
export type CalendarEventDto = Omit<Event, 'bookings'> & {
|
||||||
isModified?: boolean;
|
isModified?: boolean;
|
||||||
isCancelled?: boolean;
|
isCancelled?: boolean;
|
||||||
|
originalStartTime: Date;
|
||||||
eventBookings: BookingWithUserDto[];
|
eventBookings: BookingWithUserDto[];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -146,6 +146,7 @@ export class CalendarService {
|
|||||||
const key = `${event.id}-${event.startTime.getTime()}`;
|
const key = `${event.id}-${event.startTime.getTime()}`;
|
||||||
return {
|
return {
|
||||||
...event,
|
...event,
|
||||||
|
originalStartTime: event.startTime,
|
||||||
eventBookings: bookingMap.get(key) || [],
|
eventBookings: bookingMap.get(key) || [],
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -197,6 +198,7 @@ export class CalendarService {
|
|||||||
exception.newEndTime ||
|
exception.newEndTime ||
|
||||||
new Date(occurrenceDate.getTime() + duration),
|
new Date(occurrenceDate.getTime() + duration),
|
||||||
isModified: true,
|
isModified: true,
|
||||||
|
originalStartTime: occurrenceDate,
|
||||||
eventBookings: bookingMap.get(key) || [],
|
eventBookings: bookingMap.get(key) || [],
|
||||||
isCancelled: !!exception.isCancelled,
|
isCancelled: !!exception.isCancelled,
|
||||||
});
|
});
|
||||||
@@ -206,6 +208,7 @@ export class CalendarService {
|
|||||||
recurringOccurrences.push({
|
recurringOccurrences.push({
|
||||||
...event,
|
...event,
|
||||||
startTime: occurrenceDate,
|
startTime: occurrenceDate,
|
||||||
|
originalStartTime: occurrenceDate,
|
||||||
endTime: new Date(occurrenceDate.getTime() + duration),
|
endTime: new Date(occurrenceDate.getTime() + duration),
|
||||||
eventBookings: bookingMap.get(key) || [],
|
eventBookings: bookingMap.get(key) || [],
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user