perf: tRPC procedures and middleware refactor (#8419)
* trpc procedures an middleware refactor * allow use sessionMiddleware without a req object * sync with the new tRPC structure * tRPC refactor on routing form app * import Prisma from @prisma/client * Lazy load apps from appstore * remove unrelated changes * Add types for PaymentService * type fixes * Merge branch 'main' into roae85/cal-1514-set-the-user-session-only-on-the * fix typo * remove console.log * remove explicit types from apstore object * linter fixes --------- Co-authored-by: Keith Williams <[email protected]> Co-authored-by: Hariom Balhara <[email protected]>
This commit is contained in:
63 files changed
+1818
-1019
No files matched your search
@@ -1,39 +0,0 @@
|
||||
import type { Payment, Prisma, Booking, PaymentOption } from "@prisma/client";
|
||||
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
|
||||
export interface IAbstractPaymentService {
|
||||
/* This method is for creating charges at the time of booking */
|
||||
create(
|
||||
payment: Pick<Prisma.PaymentUncheckedCreateInput, "amount" | "currency">,
|
||||
bookingId: Booking["id"],
|
||||
bookerEmail: string,
|
||||
paymentOption: PaymentOption
|
||||
): Promise<Payment>;
|
||||
/* This method is to collect card details to charge at a later date ex. no-show fees */
|
||||
collectCard(
|
||||
payment: Pick<Prisma.PaymentUncheckedCreateInput, "amount" | "currency">,
|
||||
bookingId: Booking["id"],
|
||||
bookerEmail: string,
|
||||
paymentOption: PaymentOption
|
||||
): Promise<Payment>;
|
||||
chargeCard(
|
||||
payment: Pick<Prisma.PaymentUncheckedCreateInput, "amount" | "currency">,
|
||||
bookingId: Booking["id"]
|
||||
): Promise<Payment>;
|
||||
update(paymentId: Payment["id"], data: Partial<Prisma.PaymentUncheckedCreateInput>): Promise<Payment>;
|
||||
refund(paymentId: Payment["id"]): Promise<Payment>;
|
||||
getPaymentPaidStatus(): Promise<string>;
|
||||
getPaymentDetails(): Promise<Payment>;
|
||||
afterPayment(
|
||||
event: CalendarEvent,
|
||||
booking: {
|
||||
user: { email: string | null; name: string | null; timeZone: string } | null;
|
||||
id: number;
|
||||
startTime: { toISOString: () => string };
|
||||
uid: string;
|
||||
},
|
||||
paymentData: Payment
|
||||
): Promise<void>;
|
||||
deletePayment(paymentId: Payment["id"]): Promise<boolean>;
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import type { Payment, Prisma } from "@prisma/client";
|
||||
|
||||
import appStore from "@calcom/app-store";
|
||||
import type { AppCategories } from "@calcom/prisma/enums";
|
||||
import type { IAbstractPaymentService } from "@calcom/types/PaymentService";
|
||||
|
||||
const deletePayment = async (
|
||||
paymentId: Payment["id"],
|
||||
@@ -14,13 +15,14 @@ const deletePayment = async (
|
||||
} | null;
|
||||
}
|
||||
): Promise<boolean> => {
|
||||
const paymentApp = await appStore[paymentAppCredentials?.app?.dirName as keyof typeof appStore];
|
||||
const paymentApp = await appStore[paymentAppCredentials?.app?.dirName as keyof typeof appStore]();
|
||||
if (!(paymentApp && "lib" in paymentApp && "PaymentService" in paymentApp.lib)) {
|
||||
console.warn(`payment App service of type ${paymentApp} is not implemented`);
|
||||
return false;
|
||||
}
|
||||
const PaymentService = paymentApp.lib.PaymentService;
|
||||
const paymentInstance = new PaymentService(paymentAppCredentials);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const PaymentService = paymentApp.lib.PaymentService as any;
|
||||
const paymentInstance = new PaymentService(paymentAppCredentials) as IAbstractPaymentService;
|
||||
const deleted = await paymentInstance.deletePayment(paymentId);
|
||||
return deleted;
|
||||
};
|
||||
|
||||
@@ -4,6 +4,7 @@ import appStore from "@calcom/app-store";
|
||||
import type { EventTypeAppsList } from "@calcom/app-store/utils";
|
||||
import type { EventTypeModel } from "@calcom/prisma/zod";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
import type { IAbstractPaymentService } from "@calcom/types/PaymentService";
|
||||
|
||||
const handlePayment = async (
|
||||
evt: CalendarEvent,
|
||||
@@ -24,13 +25,15 @@ const handlePayment = async (
|
||||
},
|
||||
bookerEmail: string
|
||||
) => {
|
||||
const paymentApp = await appStore[paymentAppCredentials?.app?.dirName as keyof typeof appStore];
|
||||
const paymentApp = await appStore[paymentAppCredentials?.app?.dirName as keyof typeof appStore]();
|
||||
if (!(paymentApp && "lib" in paymentApp && "PaymentService" in paymentApp.lib)) {
|
||||
console.warn(`payment App service of type ${paymentApp} is not implemented`);
|
||||
return null;
|
||||
}
|
||||
const PaymentService = paymentApp.lib.PaymentService;
|
||||
const paymentInstance = new PaymentService(paymentAppCredentials);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const PaymentService = paymentApp.lib.PaymentService as any;
|
||||
|
||||
const paymentInstance = new PaymentService(paymentAppCredentials) as IAbstractPaymentService;
|
||||
|
||||
const paymentOption =
|
||||
selectedEventType?.metadata?.apps?.[paymentAppCredentials.appId].paymentOption || "ON_BOOKING";
|
||||
|
||||
Reference in new issue
Block a user