Scheduling infrastructure for absolutely everyone.
chore: no default export
Agusti Fernandez Pardo3011e0ecf744
diff --git a/lib/helpers/withMiddleware.ts b/lib/helpers/withMiddleware.tsindex 99f3958af73..d333439df87 100644--- a/lib/helpers/withMiddleware.ts+++ b/lib/helpers/withMiddleware.ts@@ -12,4 +12,4 @@ const withMiddleware = label(["sentry","verifyApiKey"] // <-- Provide a list of middleware to call automatically);-export default withMiddleware;\ No newline at end of file+export { withMiddleware };\ No newline at end of filediff --git a/lib/validations/shared/queryIdString.ts b/lib/validations/shared/queryIdString.tsindex c2216068415..e89986dca5d 100644--- a/lib/validations/shared/queryIdString.ts+++ b/lib/validations/shared/queryIdString.ts@@ -5,6 +5,9 @@ import { z } from "zod";// at different endpoints that require this validation.const schemaQueryIdAsString = z.object({+ // since we added apiKey as query param this is required by next-validations helper+ // for query params to work properly and not fail.+ apiKey: z.string().cuid(),// since nextjs parses query params as strings,// we need to cast them to numbers using z.transform() and parseInt()id: z.string()diff --git a/lib/validations/shared/queryIdTransformParseInt.ts b/lib/validations/shared/queryIdTransformParseInt.tsindex d185d1a2557..b1f2eb48358 100644--- a/lib/validations/shared/queryIdTransformParseInt.ts+++ b/lib/validations/shared/queryIdTransformParseInt.ts@@ -5,6 +5,9 @@ import { z } from "zod";// at different endpoints that require this validation.const schemaQueryIdParseInt = z.object({+ // since we added apiKey as query param this is required by next-validations helper+ // for query params to work properly and not fail.+ apiKey: z.string().cuid(),// since nextjs parses query params as strings,// we need to cast them to numbers using z.transform() and parseInt()id: zdiff --git a/pages/_middleware.ts b/pages/_middleware.tsindex c631934a91a..624d3920434 100644--- a/pages/_middleware.ts+++ b/pages/_middleware.ts@@ -3,7 +3,7 @@ import { NextRequest, NextResponse } from "next/server";// Not much useful yet as prisma.client can't be used in the middlewares (client is not available)// For now we just throw early if no apiKey is passed,// but we could also check if the apiKey is valid if we had prisma here.-export async function middleware({ nextUrl }: NextRequest) {+export async function requireApiKeyAsQueryParams({ nextUrl }: NextRequest) {const response = NextResponse.next();const apiKey = nextUrl.searchParams.get("apiKey");diff --git a/pages/api/users/[id]/delete.ts b/pages/api/users/[id]/delete.tsindex f7bbf96856b..1a2a2b240e8 100644--- a/pages/api/users/[id]/delete.ts+++ b/pages/api/users/[id]/delete.ts@@ -1,7 +1,8 @@-import prisma from "@calcom/prisma";import type { NextApiRequest, NextApiResponse } from "next";+import prisma from "@calcom/prisma";+import { withMiddleware } from "@lib/helpers/withMiddleware";import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";@@ -24,4 +25,4 @@ export async function deleteUser(req: NextApiRequest, res: NextApiResponse<Respo} else res.status(405).json({ message: "Only DELETE Method allowed" });}-export default withValidQueryIdTransformParseInt(deleteUser);+export default withMiddleware("addRequestId")((withValidQueryIdTransformParseInt(deleteUser)));diff --git a/pages/api/users/[id]/edit.ts b/pages/api/users/[id]/edit.tsindex cba92305438..a59a0df9401 100644--- a/pages/api/users/[id]/edit.ts+++ b/pages/api/users/[id]/edit.ts@@ -4,6 +4,7 @@ import { User } from "@calcom/prisma/client";import type { NextApiRequest, NextApiResponse } from "next";import { schemaUser, withValidUser } from "@lib/validations/user";+import { withMiddleware } from "@lib/helpers/withMiddleware";import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";type ResponseData = {@@ -29,4 +30,4 @@ export async function editUser(req: NextApiRequest, res: NextApiResponse<Respons} else res.status(405).json({ message: "Only PATCH Method allowed for updating users" });}-export default withValidQueryIdTransformParseInt(withValidUser(editUser));+export default withMiddleware("addRequestId")(withValidQueryIdTransformParseInt(withValidUser(editUser)));diff --git a/pages/api/users/[id]/index.ts b/pages/api/users/[id]/index.tsindex 61be86fe7ce..cbd088e9dfc 100644--- a/pages/api/users/[id]/index.ts+++ b/pages/api/users/[id]/index.ts@@ -4,6 +4,7 @@ import { User } from "@calcom/prisma/client";import type { NextApiRequest, NextApiResponse } from "next";import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";+import { withMiddleware } from "@lib/helpers/withMiddleware";type ResponseData = {data?: User;@@ -24,4 +25,4 @@ export async function user(req: NextApiRequest, res: NextApiResponse<ResponseDat}-export default withValidQueryIdTransformParseInt(user);+export default withMiddleware("addRequestId")(withValidQueryIdTransformParseInt(user));diff --git a/pages/api/users/index.ts b/pages/api/users/index.tsindex f431caa6c87..9c7473252fc 100644--- a/pages/api/users/index.ts+++ b/pages/api/users/index.ts@@ -1,7 +1,7 @@import prisma from "@calcom/prisma";import { User } from "@calcom/prisma/client";-import withMiddleware from "@lib/helpers/withMiddleware";+import { withMiddleware } from "@lib/helpers/withMiddleware";import type { NextApiRequest, NextApiResponse } from "next";type ResponseData = {@@ -14,4 +14,5 @@ async function user(req: NextApiRequest, res: NextApiResponse<ResponseData>) {if (data) res.status(200).json({ data });else res.status(400).json({ error: "No data found" });}+export default withMiddleware("addRequestId")(user);\ No newline at end of filediff --git a/pages/api/users/new.ts b/pages/api/users/new.tsindex 7f319e62d9d..1ad079ca446 100644--- a/pages/api/users/new.ts+++ b/pages/api/users/new.ts@@ -1,26 +1,26 @@-import prisma from "@calcom/prisma";--import { User } from "@calcom/prisma/client";import type { NextApiRequest, NextApiResponse } from "next";+import prisma from "@calcom/prisma";+import { User } from "@calcom/prisma/client";+import { withMiddleware } from "@lib/helpers/withMiddleware";import { schemaUser, withValidUser } from "@lib/validations/user";+type ResponseData = {data?: User;- message?: string;- error?: string;+ error?: object;};async function createUser(req: NextApiRequest, res: NextApiResponse<ResponseData>) {const { body, method } = req;const safe = schemaUser.safeParse(body);if (method === "POST" && safe.success) {- await prisma.user- .create({ data: safe.data })- .then((data) => res.status(201).json({ data }))- .catch((error) => res.status(400).json({ message: "Could not create user type", error: error }));- // Reject any other HTTP method than POST- } else res.status(405).json({ error: "Only POST Method allowed" });+ const data = await prisma.user+ .create({ data: safe.data })+ if (data) res.status(201).json({ data })+ else (error: unknown) => res.status(400).json({ error: { message: "Could not create user type", error: error } });+ // Reject any other HTTP method than POST+ } else res.status(405).json({ error: { message: "Only POST Method allowed" } });}-export default withValidUser(createUser);+export default withMiddleware("addRequestId")(withValidUser(createUser));