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
@@ -5,7 +5,8 @@ import { defaultAvatarSrc } from "@calcom/lib/defaultAvatarImage";
|
||||
import { _UserModel as User } from "@calcom/prisma/zod";
|
||||
import type { inferRouterOutputs } from "@calcom/trpc";
|
||||
import { TRPCError } from "@calcom/trpc";
|
||||
import { authedAdminProcedure, middleware, router } from "@calcom/trpc/server/trpc";
|
||||
import { authedAdminProcedure } from "@calcom/trpc/server/procedures/authedProcedure";
|
||||
import { router } from "@calcom/trpc/server/trpc";
|
||||
|
||||
export type UserAdminRouter = typeof userAdminRouter;
|
||||
export type UserAdminRouterOutputs = inferRouterOutputs<UserAdminRouter>;
|
||||
@@ -51,7 +52,9 @@ function exclude<UserType, Key extends keyof UserType>(user: UserType, keys: Key
|
||||
}
|
||||
|
||||
/** Reusable logic that checks for admin permissions and if the requested user exists */
|
||||
const authedAdminWithUserMiddleware = middleware(async ({ ctx, next, rawInput }) => {
|
||||
//const authedAdminWithUserMiddleware = middleware();
|
||||
|
||||
const authedAdminProcedureWithRequestedUser = authedAdminProcedure.use(async ({ ctx, next, rawInput }) => {
|
||||
const { prisma } = ctx;
|
||||
const parsed = userIdSchema.safeParse(rawInput);
|
||||
if (!parsed.success) throw new TRPCError({ code: "BAD_REQUEST", message: "User id is required" });
|
||||
@@ -68,8 +71,6 @@ const authedAdminWithUserMiddleware = middleware(async ({ ctx, next, rawInput })
|
||||
});
|
||||
});
|
||||
|
||||
const authedAdminProcedureWithRequestedUser = authedAdminProcedure.use(authedAdminWithUserMiddleware);
|
||||
|
||||
export const userAdminRouter = router({
|
||||
get: authedAdminProcedureWithRequestedUser.input(userIdSchema).query(async ({ ctx }) => {
|
||||
const { requestedUser } = ctx;
|
||||
|
||||
Reference in new issue
Block a user