refactor: evt calendar event builder (#27203)

* refactor: evt creation

* refactor: evt creation

* refactor: evt creation

* fix: type

* test: update unit tests

* chore: add comments

* fix: handle undefined in withConditional to match NonNullable<T> type

Co-Authored-By: unknown <>

* refactor: evt

* fix: type err

* refactor: remove add videoCallData

* refactor: use error with code

* test: update unit test

* refactor: feedback

* refactor: remove conditional

* refactor: more strict types

* fix: type err

* chor: remove un used

* refactor:  improve recurring event handling in RegularBookingService

Removed unnecessary whitespace and clarified comments regarding the attachment of recurring configurations in the booking handler. Adjusted logic to ensure that recurring settings are only applied when relevant.

* refactor: test

* fix: type error

* refactor: improve code

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-03-19 03:50:48 +09:00
1 parent 3c57960b7d
commit f2a44279fe
12 files changed
+512 -825

No files matched your search

@@ -1,5 +1,8 @@
import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses";
import { addVideoCallDataToEvent } from "@calcom/features/bookings/lib/handleNewBooking/addVideoCallDataToEvent";
import type { BuiltCalendarEvent } from "@calcom/features/CalendarEventBuilder";
import { CalendarEventBuilder } from "@calcom/features/CalendarEventBuilder";
import { getBookerBaseUrl } from "@calcom/features/ee/organizations/lib/getBookerUrlServer";
import { ProfileRepository } from "@calcom/features/profile/repositories/ProfileRepository";
import { getTranslation } from "@calcom/i18n/server";
import prisma from "@calcom/prisma";
import type { CalendarEvent } from "@calcom/types/Calendar";
@@ -12,6 +15,7 @@ const buildCalendarEvent: (bookingUid: string) => Promise<CalendarEvent> = async
include: {
user: {
select: {
id: true,
name: true,
email: true,
locale: true,
@@ -24,6 +28,11 @@ const buildCalendarEvent: (bookingUid: string) => Promise<CalendarEvent> = async
select: {
slug: true,
bookingFields: true,
team: {
select: {
parentId: true,
},
},
},
},
attendees: {
@@ -51,6 +60,12 @@ const buildCalendarEvent: (bookingUid: string) => Promise<CalendarEvent> = async
throw new Error(`event type not found for booking ${bookingUid}`);
}
const organizerOrganizationId = booking.eventType.team?.parentId
? booking.eventType.team.parentId
: await ProfileRepository.findFirstOrganizationIdForUser({
userId: booking.user.id,
});
const bookerUrl = await getBookerBaseUrl(organizerOrganizationId ?? null);
const organizerT = await getTranslation(booking.user?.locale ?? "en", "common");
const attendeePromises = [];
@@ -68,12 +83,13 @@ const buildCalendarEvent: (bookingUid: string) => Promise<CalendarEvent> = async
const attendeeList = await Promise.all(attendeePromises);
let calendarEvent: CalendarEvent = {
let calendarEvent: BuiltCalendarEvent = {
uid: bookingUid,
type: booking.eventType.slug,
title: booking.title,
startTime: booking.startTime.toISOString(),
endTime: booking.endTime.toISOString(),
bookerUrl,
organizer: {
email: booking.user.email,
name: booking.user.name || "Nameless",
@@ -89,7 +105,9 @@ const buildCalendarEvent: (bookingUid: string) => Promise<CalendarEvent> = async
}),
};
calendarEvent = addVideoCallDataToEvent(booking.references, calendarEvent);
calendarEvent = CalendarEventBuilder.fromEvent(calendarEvent)
.withVideoCallDataFromReferences(booking.references)
.build();
return calendarEvent;
};