Files
calendar/packages/features/bookings/lib/buildEventUrlFromBooking.ts
Benny JooandGitHub e91bf53d80 refactor: Remove circular deps between @calcom/lib and @calcom/features [2] (#24438)
* move SystemField to features

* migrate workflow service

* merge two tests for team repository

* update imports and migrate team repository

* migrate delegation credential repository

* migrate credential repository

* migrate entityPermissionUtils

* migrate hashedLink service and repository

* migrate membership service

* update imports

* remove file

* migrate buildEventUrlFromBooking

* migrate getAllUserBookings to features

* update imports

* update organizationMock

* migrate slots

* migrate date-ranges to schedules dir

* migrate getAggregatedAvailability

* fix

* refactor

* migrate useCreateEventType hook to features

* migrate assignValueToUser

* migrate validateUsername to auth features

* migrate system field back to lib

* migrate getLabelValueMapFromResponses back to lib

* update imports

* use relative path

* fix type checks

* fix

* fix

* fix tests

* update gh codeowners

* fix

* fix
2025-10-17 06:48:08 -03:00

56 lines
1.9 KiB
TypeScript

import { getBookerBaseUrl } from "@calcom/features/ee/organizations/lib/getBookerUrlServer";
import logger from "@calcom/lib/logger";
import { safeStringify } from "@calcom/lib/safeStringify";
type BookingEventType = {
slug: string;
team: {
slug: string | null;
parentId: number | null;
} | null;
};
/**
* It has its profile always set and if organizationId is null, then username would be regular(non-org) username.
*/
type ProfileEnrichedBookingUser = {
profile: { organizationId: number | null; username: string | null };
} | null;
export function getOrganizationIdOfBooking(booking: {
eventType: BookingEventType;
profileEnrichedBookingUser: ProfileEnrichedBookingUser;
}) {
const { eventType, profileEnrichedBookingUser } = booking;
return eventType.team
? eventType.team.parentId
: profileEnrichedBookingUser?.profile.organizationId ?? null;
}
export async function buildEventUrlFromBooking(booking: {
eventType: BookingEventType;
profileEnrichedBookingUser: ProfileEnrichedBookingUser;
dynamicGroupSlugRef: string | null;
}) {
const { eventType, dynamicGroupSlugRef, profileEnrichedBookingUser } = booking;
const eventSlug = eventType.slug;
const eventTeam = eventType.team;
const bookingOrganizationId = getOrganizationIdOfBooking({ eventType, profileEnrichedBookingUser });
const bookerUrl = await getBookerBaseUrl(bookingOrganizationId);
if (dynamicGroupSlugRef) {
return `${bookerUrl}/${dynamicGroupSlugRef}/${eventSlug}`;
}
if (eventTeam?.slug) {
return `${bookerUrl}/team/${eventTeam.slug}/${eventSlug}`;
}
const username = profileEnrichedBookingUser?.profile?.username;
if (!username) {
logger.error("No username found for booking user.", safeStringify({ profileEnrichedBookingUser }));
throw new Error("No username found for booking user.");
}
return `${bookerUrl}/${username}/${eventSlug}`;
}