hunk.code_window:  *        description: Authorization information is missing or invalid.
    */
   async function postHandler(req: NextApiRequest) {
     const { prisma, body, userId } = req;
     const data = schemaTeamBodyParams.parse(body);
     const team = await prisma.team.create({
       data: {
  
hunk.labels: keep keep keep keep add keep keep
hunk.after_edit:   // TODO: Perhaps there is a better fix for this?
     const cloneData: typeof data & {
       metadata: NonNullable<typeof data.metadata> | undefined;
     } = {
       ...data,
       metadata: data.metadata === null ? {} : data.metadata || undefined,
     };
  
hunk.file_path: pages/api/teams/_post.ts
hunk.type: add
file: import type { NextApiRequest } from "next";
  
  import { HttpError } from "@calcom/lib/http-error";
  
  import { schemaQueryIdParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
  
  async function authMiddleware(req: NextApiRequest) {
    const { userId, prisma, isAdmin, query } = req;
    const { id } = schemaQueryIdParseInt.parse(query);
    const userWithBookings = await prisma.user.findUnique({
      where: { id: userId },
      include: { bookings: true },
    });
  
    if (!userWithBookings) throw new HttpError({ statusCode: 404, message: "User not found" });
  
    const userBookingIds = userWithBookings.bookings.map((booking) => booking.id);
  
    if (!isAdmin && !userBookingIds.includes(id)) {
      throw new HttpError({ statusCode: 401, message: "You are not authorized" });
    }
  }
  
  export default authMiddleware;
  