refactor: companion event type query parameters (#27125)

This commit is contained in:
Dhairyashil Shinde
2026-01-22 09:00:23 -03:00
committed by GitHub
parent 509ceeaa86
commit a63bf11c3f
2 changed files with 6 additions and 57 deletions
@@ -933,34 +933,9 @@ async function getAuthHeader(): Promise<string> {
async function fetchEventTypes(): Promise<unknown[]> {
const authHeader = await getAuthHeader();
const userResponse = await fetchWithTimeout(`${API_BASE_URL}/me`, {
headers: {
Authorization: authHeader,
"Content-Type": "application/json",
"cal-api-version": "2024-06-11",
},
});
if (!userResponse.ok) {
throw new Error(`Failed to get user: ${userResponse.statusText}`);
}
const userData = await userResponse.json();
const username = userData?.data?.username as string | undefined;
// For org users, include org slug to avoid username collisions across orgs
const orgSlug = userData?.data?.organization?.slug as string | undefined;
const params = new URLSearchParams();
if (username) {
params.append("username", username);
}
if (orgSlug) {
params.append("orgSlug", orgSlug);
}
const queryString = params.toString();
const endpoint = `${API_BASE_URL}/event-types${queryString ? `?${queryString}` : ""}`;
const response = await fetchWithTimeout(endpoint, {
// For authenticated users, no username/orgSlug params needed - API uses auth token
// This also ensures hidden event types are returned (they're filtered out when username is provided)
const response = await fetchWithTimeout(`${API_BASE_URL}/event-types`, {
headers: {
Authorization: authHeader,
"Content-Type": "application/json",
+3 -29
View File
@@ -862,36 +862,10 @@ async function getTranscripts(bookingUid: string): Promise<BookingTranscript[]>
}
async function getEventTypes(): Promise<EventType[]> {
// Get cached user profile to extract username and org slug (uses in-flight deduplication)
let username: string | undefined;
let orgSlug: string | undefined;
try {
const userProfile = await getUserProfile();
// Extract username from response
if (userProfile?.username) {
username = userProfile.username;
}
// For org users, include org slug to avoid username collisions across orgs
if (userProfile?.organization?.slug) {
orgSlug = userProfile.organization.slug;
}
} catch (_error) {}
// Build query string with username, orgSlug, and sorting
const params = new URLSearchParams();
if (username) {
params.append("username", username);
}
if (orgSlug) {
params.append("orgSlug", orgSlug);
}
// For authenticated users, no username/orgSlug params needed - API uses auth token
// This also ensures hidden event types are returned (they're filtered out when username is provided)
// Sort by creation date descending (newer first) to match main codebase behavior
// Main codebase uses position: "desc", id: "desc" - since API doesn't expose position,
// we use sortCreatedAt: "desc" for similar behavior (newer event types first)
params.append("sortCreatedAt", "desc");
const queryString = params.toString();
const endpoint = `/event-types${queryString ? `?${queryString}` : ""}`;
const endpoint = `/event-types?sortCreatedAt=desc`;
const response = await makeRequest<unknown>(endpoint, {}, "2024-06-14");