From 5b28e9ec1c8ce6c53172f725a2da6f8d509e6adf Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Sat, 18 Jun 2022 02:16:15 +0200 Subject: [PATCH] fix: main merging issues --- lib/helpers/extendRequest.ts | 1 - lib/helpers/withMiddleware.ts | 2 +- next.config.js | 1 + pages/api/availabilities/[id].ts | 2 +- pages/api/users/index.ts | 58 -------------------------------- 5 files changed, 3 insertions(+), 61 deletions(-) diff --git a/lib/helpers/extendRequest.ts b/lib/helpers/extendRequest.ts index 52af6da544..8ed3ee0571 100644 --- a/lib/helpers/extendRequest.ts +++ b/lib/helpers/extendRequest.ts @@ -18,6 +18,5 @@ declare module "next" { } } export const extendRequest: NextMiddleware = async (req, res, next) => { - // @note: just an empty middleware, we care about extending the next api request types only. await next(); }; diff --git a/lib/helpers/withMiddleware.ts b/lib/helpers/withMiddleware.ts index 05b21cbf0d..ab6d5cb79e 100644 --- a/lib/helpers/withMiddleware.ts +++ b/lib/helpers/withMiddleware.ts @@ -29,7 +29,7 @@ const withMiddleware = label( sentry: captureErrors, }, // The order here, determines the order of execution, put customPrismaClient before verifyApiKey always. - ["sentry", "customPrismaClient", "verifyApiKey", "addRequestId", "extendRequest"] // <-- Provide a list of middleware to call automatically + ["extendRequest", "sentry", "customPrismaClient", "verifyApiKey", "addRequestId"] // <-- Provide a list of middleware to call automatically ); export { withMiddleware }; diff --git a/next.config.js b/next.config.js index 22ff466595..939eba2374 100644 --- a/next.config.js +++ b/next.config.js @@ -3,6 +3,7 @@ const withTM = require("next-transpile-modules")([ "@calcom/app-store", "@calcom/core", + "@calcom/console", "@calcom/ee", "@calcom/lib", "@calcom/prisma", diff --git a/pages/api/availabilities/[id].ts b/pages/api/availabilities/[id].ts index fe62182978..1d4b6ed4a1 100644 --- a/pages/api/availabilities/[id].ts +++ b/pages/api/availabilities/[id].ts @@ -1,6 +1,6 @@ import type { NextApiRequest, NextApiResponse } from "next"; -// import { withMiddleware } from "@lib/helpers/withMiddleware"; +import { withMiddleware } from "@lib/helpers/withMiddleware"; import type { AvailabilityResponse } from "@lib/types"; import { schemaAvailabilityEditBodyParams, diff --git a/pages/api/users/index.ts b/pages/api/users/index.ts index 28231b487a..c07846423f 100644 --- a/pages/api/users/index.ts +++ b/pages/api/users/index.ts @@ -1,68 +1,10 @@ -<<<<<<< HEAD -import type { NextApiRequest, NextApiResponse } from "next"; -======= import { defaultHandler } from "@calcom/lib/server"; ->>>>>>> main import { withMiddleware } from "@lib/helpers/withMiddleware"; -<<<<<<< HEAD -/** - * @swagger - * /users: - * get: - * operationId: listUsers - * summary: Find all users. - * tags: - * - users - * responses: - * 200: - * description: OK - * 401: - * description: Authorization information is missing or invalid. - * 404: - * description: No users were found - */ -async function getAllorCreateUser( - { userId, method, body, prisma }: NextApiRequest, - res: NextApiResponse -) { - const isAdmin = await isAdminGuard(userId); - if (method === "GET") { - if (!isAdmin) { - // If user is not ADMIN, return only his data. - const data = await prisma.user.findMany({ where: { id: userId } }); - const users = data.map((user) => schemaUserReadPublic.parse(user)); - if (users) res.status(200).json({ users }); - } else { - // If user is admin, return all users. - const data = await prisma.user.findMany({}); - const users = data.map((user) => schemaUserReadPublic.parse(user)); - if (users) res.status(200).json({ users }); - } - } else if (method === "POST") { - // If user is not ADMIN, return unauthorized. - if (!isAdmin) res.status(401).json({ message: "You are not authorized" }); - else { - const safeBody = schemaUserCreateBodyParams.safeParse(body); - if (!safeBody.success) { - res.status(400).json({ message: "Your body was invalid" }); - return; - } - const user = await prisma.user.create({ - data: safeBody.data, - }); - res.status(201).json({ user }); - } - } -} - -export default withMiddleware("HTTP_GET_OR_POST")(getAllorCreateUser); -======= export default withMiddleware("HTTP_GET_OR_POST")( defaultHandler({ GET: import("./_get"), POST: import("./_post"), }) ); ->>>>>>> main