hunk.code_window:  *                 example: My Event
    *               slug:
    *                 type: string
    *                 example: my-event
    *     tags:
    *     - event-types
    *     externalDocs:
  
hunk.labels: keep keep keep add keep keep keep
hunk.after_edit:  *
  
hunk.file_path: pages/api/event-types/_post.ts
hunk.type: add
file: import type { NextApiRequest } from "next";
  
  import { HttpError } from "@calcom/lib/http-error";
  
  import { schemaQueryIdAsString } from "~/lib/validations/shared/queryIdString";
  
  async function authMiddleware(req: NextApiRequest) {
    const { userId, isAdmin, prisma } = req;
    const { id } = schemaQueryIdAsString.parse(req.query);
    // Admins can just skip this check
    if (isAdmin) return;
    // Check if the current user can access the webhook
    const webhook = await prisma.webhook.findFirst({
      where: { id, appId: null, OR: [{ userId }, { eventType: { team: { members: { some: { userId } } } } }] },
    });
    if (!webhook) throw new HttpError({ statusCode: 403, message: "Forbidden" });
  }
  
  export default authMiddleware;
  