2022-03-26 00:53:56 +00:00
|
|
|
import prisma from "@calcom/prisma";
|
|
|
|
|
|
|
|
import { Team } from "@calcom/prisma/client";
|
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
|
2022-03-26 23:58:22 +00:00
|
|
|
import { schemaQueryIdParseInt, withValidQueryIdTransformParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
2022-03-26 00:53:56 +00:00
|
|
|
|
|
|
|
type ResponseData = {
|
|
|
|
data?: Team;
|
|
|
|
message?: string;
|
|
|
|
error?: unknown;
|
|
|
|
};
|
|
|
|
|
|
|
|
export async function team(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
|
|
|
|
const { query, method } = req;
|
2022-03-26 23:58:22 +00:00
|
|
|
const safe = await schemaQueryIdParseInt.safeParse(query);
|
|
|
|
|
|
|
|
if (method === "GET" && safe.success) {
|
|
|
|
const team = await prisma.team.findUnique({ where: { id: safe.data.id } });
|
2022-03-26 00:53:56 +00:00
|
|
|
|
2022-03-26 23:58:22 +00:00
|
|
|
if (team) res.status(200).json({ data: team });
|
|
|
|
if (!team) res.status(404).json({ message: "Event type not found" });
|
|
|
|
} else {
|
|
|
|
// Reject any other HTTP method than POST
|
|
|
|
res.status(405).json({ message: "Only GET Method allowed" });
|
2022-03-26 00:53:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default withValidQueryIdTransformParseInt(team);
|