Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions packages/trpc/src/utils/rescheduling-availability.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { getAvailableSlots } from "@calcom/lib/availability";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Import a real slot API before wiring this utility

getAvailableSlots is imported from @calcom/lib/availability, but that module does not export a symbol with this name (see packages/lib/availability.ts exports). As soon as this utility is actually connected to runtime code, it will fail to build/load due to the missing export, blocking the feature.

Useful? React with 👍 / 👎.

import { prisma } from "@calcom/prisma";
import dayjs from "@calcom/lib/dayjs";
import { EventType } from "@calcom/types/EventType";

export interface ReschedulingAvailabilityParams {
hostUserId: number;
guestEmail: string;
eventType: EventType;
dateFrom: Date;
dateTo: Date;
timeZone: string;
}

/**
* Retrieves available slots for rescheduling considering both host and guest availability.
* If guest is not a Cal.com user, returns host's availability only (fallback to original behavior).
* Returns string[] of ISO 8601 timestamps (e.g., "2024-01-15T10:00:00.000Z")
*/
export async function getReschedulingAvailableSlots({
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Move and invoke this helper from compiled reschedule flow

This function is currently a no-op for production behavior: it lives under packages/trpc/src, but packages/trpc/tsconfig.json only includes ./server, and there are no call sites for getReschedulingAvailableSlots in the repo. That means the guest-availability filtering described by the PR never executes, so rescheduling behavior remains unchanged.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0: getReschedulingAvailableSlots is exported but has no call sites in the codebase. The guest availability filtering described by this PR never executes — rescheduling behavior remains unchanged. This utility needs to be imported and invoked from the actual reschedule flow (e.g., a tRPC handler or API route) for the feature to work.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/trpc/src/utils/rescheduling-availability.ts, line 20:

<comment>`getReschedulingAvailableSlots` is exported but has no call sites in the codebase. The guest availability filtering described by this PR never executes — rescheduling behavior remains unchanged. This utility needs to be imported and invoked from the actual reschedule flow (e.g., a tRPC handler or API route) for the feature to work.</comment>

<file context>
@@ -0,0 +1,75 @@
+ * If guest is not a Cal.com user, returns host's availability only (fallback to original behavior).
+ * Returns string[] of ISO 8601 timestamps (e.g., "2024-01-15T10:00:00.000Z")
+ */
+export async function getReschedulingAvailableSlots({
+  hostUserId,
+  guestEmail,
</file context>
Fix with Cubic

hostUserId,
guestEmail,
eventType,
dateFrom,
dateTo,
timeZone,
}: ReschedulingAvailabilityParams): Promise<string[]> {
// Fetch host availability first (always needed)
let hostSlots: string[] = [];
try {
hostSlots = await getAvailableSlots({
userId: hostUserId,
dateFrom,
dateTo,
eventType,
timeZone,
});
} catch (error) {
console.error("Failed to fetch host availability:", error);
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Custom agent: Avoid Logging Sensitive Information

Do not log raw error objects here; sanitize logging to avoid leaking PII or integration secrets from availability failures.

(Based on your team's feedback about avoiding raw error-object logging that may expose sensitive data.)

View Feedback

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/trpc/src/utils/rescheduling-availability.ts, line 39:

<comment>Do not log raw error objects here; sanitize logging to avoid leaking PII or integration secrets from availability failures.

(Based on your team's feedback about avoiding raw error-object logging that may expose sensitive data.) </comment>

<file context>
@@ -0,0 +1,75 @@
+      timeZone,
+    });
+  } catch (error) {
+    console.error("Failed to fetch host availability:", error);
+    return [];
+  }
</file context>
Fix with Cubic

return [];
}

// Check if guest is a Cal.com user by email
const guestUser = await prisma.user.findUnique({
where: { email: guestEmail },
select: { id: true },
});

// If guest is not a Cal.com user, return host slots (original behavior)
if (!guestUser) {
return hostSlots;
}

// Guest is a Cal.com user: fetch their availability
let guestSlots: string[] = [];
try {
guestSlots = await getAvailableSlots({
userId: guestUser.id,
dateFrom,
dateTo,
eventType,
timeZone,
});
} catch (error) {
console.error("Failed to fetch guest availability:", error);
// If guest availability fetch fails, fallback to host slots (safer than blocking rescheduling)
return hostSlots;
}

// Intersect host and guest slots (only slots available for both)
const availableSet = new Set(guestSlots);
const intersectedSlots = hostSlots.filter((slot) => availableSet.has(slot));

return intersectedSlots;
}
Loading