chore: refactor to use createRouterCaller util (#20494)
* create createRouterCaller and use it * fix
This commit is contained in:
1 parent
fad5497363
commit
25534f721a
6 files changed
+25
-29
No files matched your search
@@ -2,10 +2,19 @@ import { cookies, headers } from "next/headers";
|
||||
|
||||
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
import { createContext } from "@calcom/trpc/server/createContext";
|
||||
import { createCallerFactory } from "@calcom/trpc/server/trpc";
|
||||
|
||||
import { buildLegacyRequest } from "@lib/buildLegacyCtx";
|
||||
|
||||
export const getTRPCContext = async () => {
|
||||
import type { AnyRouter } from "@trpc/server";
|
||||
|
||||
const getTRPCContext = async () => {
|
||||
const legacyReq = buildLegacyRequest(await headers(), await cookies());
|
||||
return await createContext({ req: legacyReq, res: {} as any }, getServerSession);
|
||||
};
|
||||
|
||||
export async function createRouterCaller<TRouter extends AnyRouter>(router: TRouter) {
|
||||
const trpcContext = await getTRPCContext();
|
||||
const createCaller = createCallerFactory<TRouter>(router);
|
||||
return createCaller(trpcContext);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { EmbedProps } from "app/WithEmbedSSR";
|
||||
import { getTRPCContext } from "app/_trpc/context";
|
||||
import { createRouterCaller } from "app/_trpc/context";
|
||||
import type { GetServerSidePropsContext } from "next";
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -12,7 +12,6 @@ import slugify from "@calcom/lib/slugify";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { RedirectType } from "@calcom/prisma/enums";
|
||||
import { publicViewerRouter } from "@calcom/trpc/server/routers/publicViewer/_router";
|
||||
import { createCallerFactory } from "@calcom/trpc/server/trpc";
|
||||
|
||||
import { getTemporaryOrgRedirect } from "@lib/getTemporaryOrgRedirect";
|
||||
import type { inferSSRProps } from "@lib/types/inferSSRProps";
|
||||
@@ -115,9 +114,8 @@ async function getUserPageProps(context: GetServerSidePropsContext) {
|
||||
|
||||
// We use this to both prefetch the query on the server,
|
||||
// as well as to check if the event exist, so we c an show a 404 otherwise.
|
||||
const trpcContext = await getTRPCContext();
|
||||
const createCaller = createCallerFactory(publicViewerRouter);
|
||||
const caller = createCaller(trpcContext);
|
||||
const caller = await createRouterCaller(publicViewerRouter);
|
||||
|
||||
const eventData = await caller.event({
|
||||
username: name,
|
||||
eventSlug: slug,
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { getTRPCContext } from "app/_trpc/context";
|
||||
import { createRouterCaller } from "app/_trpc/context";
|
||||
import type { GetServerSidePropsContext } from "next";
|
||||
|
||||
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { eventTypesRouter } from "@calcom/trpc/server/routers/viewer/eventTypes/_router";
|
||||
import { createCallerFactory } from "@calcom/trpc/server/trpc";
|
||||
|
||||
import { asStringOrThrow } from "@lib/asStringOrNull";
|
||||
import type { inferSSRProps } from "@lib/types/inferSSRProps";
|
||||
@@ -37,9 +36,8 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||
return redirect;
|
||||
}
|
||||
const getEventTypeById = async (eventTypeId: number) => {
|
||||
const trpcContext = await getTRPCContext();
|
||||
const createCaller = createCallerFactory(eventTypesRouter);
|
||||
const caller = createCaller(trpcContext);
|
||||
const caller = await createRouterCaller(eventTypesRouter);
|
||||
|
||||
try {
|
||||
const { eventType } = await caller.get({ id: eventTypeId });
|
||||
return eventType;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getTRPCContext } from "app/_trpc/context";
|
||||
import { createRouterCaller } from "app/_trpc/context";
|
||||
import type { GetServerSidePropsContext } from "next";
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -8,7 +8,6 @@ import { orgDomainConfig } from "@calcom/features/ee/organizations/lib/orgDomain
|
||||
import slugify from "@calcom/lib/slugify";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { publicViewerRouter } from "@calcom/trpc/server/routers/publicViewer/_router";
|
||||
import { createCallerFactory } from "@calcom/trpc/server/trpc";
|
||||
|
||||
const paramsSchema = z.object({
|
||||
type: z.string().transform((s) => slugify(s)),
|
||||
@@ -39,9 +38,9 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||
}
|
||||
|
||||
const org = isValidOrgDomain ? currentOrgDomain : null;
|
||||
const trpcContext = await getTRPCContext();
|
||||
const createCaller = createCallerFactory(publicViewerRouter);
|
||||
const caller = createCaller(trpcContext);
|
||||
|
||||
const caller = await createRouterCaller(publicViewerRouter);
|
||||
|
||||
const eventData = await caller.event({
|
||||
username: teamSlug,
|
||||
eventSlug: meetingSlug,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getTRPCContext } from "app/_trpc/context";
|
||||
import { createRouterCaller } from "app/_trpc/context";
|
||||
import type { GetServerSidePropsContext } from "next";
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -13,7 +13,6 @@ import { BookingRepository } from "@calcom/lib/server/repository/booking";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { customInputSchema, EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
||||
import { meRouter } from "@calcom/trpc/server/routers/viewer/me/_router";
|
||||
import { createCallerFactory } from "@calcom/trpc/server/trpc";
|
||||
|
||||
import type { inferSSRProps } from "@lib/types/inferSSRProps";
|
||||
|
||||
@@ -51,9 +50,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
|
||||
let userTimeFormat: number | null = null;
|
||||
let requiresLoginToUpdate = false;
|
||||
if (session) {
|
||||
const trpcContext = await getTRPCContext();
|
||||
const createCaller = createCallerFactory(meRouter);
|
||||
const caller = createCaller(trpcContext);
|
||||
const caller = await createRouterCaller(meRouter);
|
||||
const user = await caller.get();
|
||||
tz = user.timeZone;
|
||||
userTimeFormat = user.timeFormat;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getTRPCContext } from "app/_trpc/context";
|
||||
import { createRouterCaller } from "app/_trpc/context";
|
||||
import { type GetServerSidePropsContext } from "next";
|
||||
import type { Session } from "next-auth";
|
||||
import { z } from "zod";
|
||||
@@ -14,7 +14,6 @@ import slugify from "@calcom/lib/slugify";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { RedirectType } from "@calcom/prisma/client";
|
||||
import { publicViewerRouter } from "@calcom/trpc/server/routers/publicViewer/_router";
|
||||
import { createCallerFactory } from "@calcom/trpc/server/trpc";
|
||||
|
||||
import { getTemporaryOrgRedirect } from "@lib/getTemporaryOrgRedirect";
|
||||
|
||||
@@ -134,9 +133,7 @@ async function getDynamicGroupPageProps(context: GetServerSidePropsContext) {
|
||||
|
||||
// We use this to both prefetch the query on the server,
|
||||
// as well as to check if the event exist, so we c an show a 404 otherwise.
|
||||
const trpcContext = await getTRPCContext();
|
||||
const createCaller = createCallerFactory(publicViewerRouter);
|
||||
const caller = createCaller(trpcContext);
|
||||
const caller = await createRouterCaller(publicViewerRouter);
|
||||
const eventData = await caller.event({
|
||||
username: usernames.join("+"),
|
||||
eventSlug: slug,
|
||||
@@ -230,9 +227,7 @@ async function getUserPageProps(context: GetServerSidePropsContext) {
|
||||
const org = isValidOrgDomain ? currentOrgDomain : null;
|
||||
// We use this to both prefetch the query on the server,
|
||||
// as well as to check if the event exist, so we can show a 404 otherwise.
|
||||
const trpcContext = await getTRPCContext();
|
||||
const createCaller = createCallerFactory(publicViewerRouter);
|
||||
const caller = createCaller(trpcContext);
|
||||
const caller = await createRouterCaller(publicViewerRouter);
|
||||
const eventData = await caller.event({
|
||||
username,
|
||||
eventSlug: slug,
|
||||
|
||||
Reference in new issue
Block a user