fix: circular dependencies (#20378)

* fix: circular dependencies

* fix: type err
This commit is contained in:
Udit Takkar authored and GitHub committed 2025-03-26 12:42:40 -04:00
1 parent d04f10e7d1
commit 596e9b4e5a
20 files changed
+158 -146

No files matched your search

@@ -0,0 +1,104 @@
import { workflowSelect } from "@calcom/features/ee/workflows/lib/getAllWorkflows";
import prisma, { bookingMinimalSelect } from "@calcom/prisma";
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
export async function getBookingToDelete(id: number | undefined, uid: string | undefined) {
return await prisma.booking.findUniqueOrThrow({
where: {
id,
uid,
},
select: {
...bookingMinimalSelect,
recurringEventId: true,
userId: true,
user: {
select: {
id: true,
username: true,
credentials: { select: credentialForCalendarServiceSelect }, // Not leaking at the moment, be careful with
email: true,
timeZone: true,
timeFormat: true,
name: true,
destinationCalendar: true,
},
},
location: true,
references: {
select: {
uid: true,
type: true,
externalCalendarId: true,
credentialId: true,
thirdPartyRecurringEventId: true,
delegationCredentialId: true,
},
},
payment: true,
paid: true,
eventType: {
select: {
slug: true,
owner: {
select: {
id: true,
hideBranding: true,
},
},
team: {
select: {
id: true,
name: true,
parentId: true,
},
},
parentId: true,
parent: {
select: {
teamId: true,
},
},
userId: true,
recurringEvent: true,
title: true,
eventName: true,
description: true,
requiresConfirmation: true,
price: true,
currency: true,
length: true,
seatsPerTimeSlot: true,
bookingFields: true,
seatsShowAttendees: true,
metadata: true,
schedulingType: true,
hosts: {
select: {
user: true,
},
},
workflows: {
select: {
workflow: {
select: workflowSelect,
},
},
},
},
},
uid: true,
id: true,
eventTypeId: true,
destinationCalendar: true,
smsReminderNumber: true,
workflowReminders: true,
seatsReferences: true,
responses: true,
iCalUID: true,
iCalSequence: true,
},
});
}
export type BookingToDelete = Awaited<ReturnType<typeof getBookingToDelete>>;
@@ -6,7 +6,6 @@ import { DailyLocationType } from "@calcom/app-store/locations";
import dayjs from "@calcom/dayjs";
import { sendCancelledEmailsAndSMS } from "@calcom/emails";
import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses";
import { workflowSelect } from "@calcom/features/ee/workflows/lib/getAllWorkflows";
import { sendCancelledReminders } from "@calcom/features/ee/workflows/lib/reminders/reminderScheduler";
import type { GetSubscriberOptions } from "@calcom/features/webhooks/lib/getWebhooks";
import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";
@@ -25,133 +24,22 @@ import { safeStringify } from "@calcom/lib/safeStringify";
import { getTranslation } from "@calcom/lib/server/i18n";
import { WorkflowRepository } from "@calcom/lib/server/repository/workflow";
import { getTimeFormatStringFromUserTimeFormat } from "@calcom/lib/timeFormat";
import prisma, { bookingMinimalSelect } from "@calcom/prisma";
import prisma from "@calcom/prisma";
import type { WebhookTriggerEvents } from "@calcom/prisma/enums";
import { BookingStatus } from "@calcom/prisma/enums";
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
import { bookingMetadataSchema, EventTypeMetaDataSchema, bookingCancelInput } from "@calcom/prisma/zod-utils";
import type { EventTypeMetadata } from "@calcom/prisma/zod-utils";
import { getAllWorkflowsFromEventType } from "@calcom/trpc/server/routers/viewer/workflows/util";
import type { CalendarEvent } from "@calcom/types/Calendar";
import { getAllCredentials } from "./getAllCredentialsForUsersOnEvent/getAllCredentials";
import { getBookingToDelete } from "./getBookingToDelete";
import type { CustomRequest, AppRouterRequest } from "./handleCancelBooking/types";
import { handleInternalNote } from "./handleInternalNote";
import cancelAttendeeSeat from "./handleSeats/cancel/cancelAttendeeSeat";
const log = logger.getSubLogger({ prefix: ["handleCancelBooking"] });
async function getBookingToDelete(id: number | undefined, uid: string | undefined) {
return await prisma.booking.findUniqueOrThrow({
where: {
id,
uid,
},
select: {
...bookingMinimalSelect,
recurringEventId: true,
userId: true,
user: {
select: {
id: true,
username: true,
credentials: { select: credentialForCalendarServiceSelect }, // Not leaking at the moment, be careful with
email: true,
timeZone: true,
timeFormat: true,
name: true,
destinationCalendar: true,
},
},
location: true,
references: {
select: {
uid: true,
type: true,
externalCalendarId: true,
credentialId: true,
thirdPartyRecurringEventId: true,
delegationCredentialId: true,
},
},
payment: true,
paid: true,
eventType: {
select: {
slug: true,
owner: {
select: {
id: true,
hideBranding: true,
},
},
team: {
select: {
id: true,
name: true,
parentId: true,
},
},
parentId: true,
parent: {
select: {
teamId: true,
},
},
userId: true,
recurringEvent: true,
title: true,
eventName: true,
description: true,
requiresConfirmation: true,
price: true,
currency: true,
length: true,
seatsPerTimeSlot: true,
bookingFields: true,
seatsShowAttendees: true,
metadata: true,
schedulingType: true,
hosts: {
select: {
user: true,
},
},
workflows: {
select: {
workflow: {
select: workflowSelect,
},
},
},
},
},
uid: true,
id: true,
eventTypeId: true,
destinationCalendar: true,
smsReminderNumber: true,
workflowReminders: true,
seatsReferences: true,
responses: true,
iCalUID: true,
iCalSequence: true,
},
});
}
export type BookingToDelete = Awaited<ReturnType<typeof getBookingToDelete>>;
export type AppRouterRequest = { appDirRequestBody: unknown };
export type CustomRequest = (NextApiRequest | AppRouterRequest) & {
userId?: number;
bookingToDelete?: BookingToDelete;
platformClientId?: string;
platformRescheduleUrl?: string;
platformCancelUrl?: string;
platformBookingUrl?: string;
arePlatformEmailsEnabled?: boolean;
};
export type HandleCancelBookingResponse = {
success: boolean;
message: string;
@@ -0,0 +1,14 @@
import type { NextApiRequest } from "next";
import type { BookingToDelete } from "../getBookingToDelete";
export type AppRouterRequest = { appDirRequestBody: unknown };
export type CustomRequest = (NextApiRequest | AppRouterRequest) & {
userId?: number;
bookingToDelete?: BookingToDelete;
platformClientId?: string;
platformRescheduleUrl?: string;
platformCancelUrl?: string;
platformBookingUrl?: string;
arePlatformEmailsEnabled?: boolean;
};
@@ -1,7 +1,7 @@
import { HttpError } from "@calcom/lib/http-error";
import prisma from "@calcom/prisma";
import { type BookingToDelete } from "./handleCancelBooking";
import type { BookingToDelete } from "./getBookingToDelete";
type InternalNote = {
id: number;
@@ -18,7 +18,7 @@ import { bookingCancelAttendeeSeatSchema } from "@calcom/prisma/zod-utils";
import type { EventTypeMetadata } from "@calcom/prisma/zod-utils";
import type { CalendarEvent } from "@calcom/types/Calendar";
import type { AppRouterRequest, CustomRequest } from "../../handleCancelBooking";
import type { AppRouterRequest, CustomRequest } from "../../handleCancelBooking/types";
async function cancelAttendeeSeat(
req: CustomRequest,
@@ -1,10 +1,11 @@
import { DataTableSelectionBar } from "@calcom/features/data-table";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { trpc } from "@calcom/trpc/react";
import type { RouterOutputs } from "@calcom/trpc/react";
import { Dialog, DialogTrigger, ConfirmationDialogContent } from "@calcom/ui/components/dialog";
import { showToast } from "@calcom/ui/components/toast";
import type { User } from "./MemberList";
export type User = RouterOutputs["viewer"]["teams"]["listMembers"]["members"][number];
interface Props {
users: User[];