Files
calendar/packages/lib/formatCalendarEvent.ts
T
52a5afeba5 fix: different calendar hosts (#24000)
* fis: pass the missing `platformClientId` to `handleNewBooking` in api/v2

* Update formatCalendarEvent.ts

* only add the externald in case of same calendar, otherwise add if from the .ics file sent in email

* Revert "fis: pass the missing `platformClientId` to `handleNewBooking` in api/v2"

This reverts commit 030ac0f0981c1135d4973fbdafa62d58e8985831.

* fix: alow the host change logic to run for collective envets as well

* fix: run the changedOrganizer logic for both collective and round-robin events

* Update handleNewBooking.ts

* fix: failing unit test

---------

Co-authored-by: Lauris Skraucis <lauris.skraucis@gmail.com>
2025-10-01 12:15:34 +03:00

50 lines
1.7 KiB
TypeScript

// eslint-disable-next-line no-restricted-imports
import { cloneDeep } from "lodash";
import type { ExtendedCalendarEvent } from "@calcom/ee/workflows/lib/reminders/reminderScheduler";
import type { CalendarEvent } from "@calcom/types/Calendar";
// format CalEvent to remove platformClientId from email addresses
const formatClientIdFromEmails = (calEvent: CalendarEvent | ExtendedCalendarEvent, clientId: string) => {
const attendees = calEvent.attendees.map((attendee) => ({
...attendee,
email: attendee.email.replace(`+${clientId}`, ""),
}));
const organizer = {
...calEvent.organizer,
email: calEvent.organizer.email.replace(`+${clientId}`, ""),
};
const team = calEvent.team
? {
...calEvent.team,
members: calEvent.team.members.map((member) => {
return {
...member,
email: member.email.replace(`+${clientId}`, ""),
};
}),
}
: undefined;
return [attendees, organizer, team];
};
export const formatCalEvent = (calEvent: CalendarEvent) => {
const clonedEvent = cloneDeep(calEvent);
if (clonedEvent.platformClientId) {
const [attendees, organizer, team] = formatClientIdFromEmails(clonedEvent, clonedEvent.platformClientId);
Object.assign(clonedEvent, { attendees, organizer, team });
}
return clonedEvent;
};
export const formatCalEventExtended = (calEvent: ExtendedCalendarEvent) => {
const clonedEvent = cloneDeep(calEvent);
if (clonedEvent.platformClientId) {
const [attendees, organizer, team] = formatClientIdFromEmails(clonedEvent, clonedEvent.platformClientId);
Object.assign(clonedEvent, { attendees, organizer, team });
}
return clonedEvent;
};