* 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 <keithwillcode@gmail.com> Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
30 lines
916 B
TypeScript
30 lines
916 B
TypeScript
import authedProcedure from "../../../procedures/authedProcedure";
|
|
import { router } from "../../../trpc";
|
|
import { ZChargerCardInputSchema } from "./chargeCard.schema";
|
|
|
|
interface PaymentsRouterHandlerCache {
|
|
chargeCard?: typeof import("./chargeCard.handler").chargeCardHandler;
|
|
}
|
|
|
|
const UNSTABLE_HANDLER_CACHE: PaymentsRouterHandlerCache = {};
|
|
|
|
export const paymentsRouter = router({
|
|
chargeCard: authedProcedure.input(ZChargerCardInputSchema).mutation(async ({ ctx, input }) => {
|
|
if (!UNSTABLE_HANDLER_CACHE.chargeCard) {
|
|
UNSTABLE_HANDLER_CACHE.chargeCard = await import("./chargeCard.handler").then(
|
|
(mod) => mod.chargeCardHandler
|
|
);
|
|
}
|
|
|
|
// Unreachable code but required for type safety
|
|
if (!UNSTABLE_HANDLER_CACHE.chargeCard) {
|
|
throw new Error("Failed to load handler");
|
|
}
|
|
|
|
return UNSTABLE_HANDLER_CACHE.chargeCard({
|
|
ctx,
|
|
input,
|
|
});
|
|
}),
|
|
});
|