cal.pub0.org/pages/api/teams/[id]/index.ts

31 lines
906 B
TypeScript
Raw Normal View History

import prisma from "@calcom/prisma";
import { Team } 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?: Team;
message?: string;
error?: unknown;
};
export async function teamById(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
const safe = await schemaQueryIdParseInt.safeParse(req.query);
if (safe.success) {
const data = await prisma.team.findUnique({ where: { id: safe.data.id } });
if (data) res.status(200).json({ data });
else res.status(404).json({ message: "Team was not found" });
}
}
export default withMiddleware("addRequestId","getOnly")(
withValidQueryIdTransformParseInt(
teamById
)
);