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-29 01:59:57 +00:00
|
|
|
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
2022-03-26 00:53:56 +00:00
|
|
|
|
|
|
|
type ResponseData = {
|
|
|
|
data?: Team;
|
|
|
|
message?: string;
|
|
|
|
error?: unknown;
|
|
|
|
};
|
|
|
|
|
2022-03-29 01:59:57 +00:00
|
|
|
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 } });
|
2022-03-26 00:53:56 +00:00
|
|
|
|
2022-03-29 01:59:57 +00:00
|
|
|
if (data) res.status(200).json({ data });
|
|
|
|
else res.status(404).json({ message: "Team was not found" });
|
2022-03-26 00:53:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-29 01:59:57 +00:00
|
|
|
export default withMiddleware("addRequestId","getOnly")(
|
|
|
|
withValidQueryIdTransformParseInt(
|
|
|
|
teamById
|
|
|
|
)
|
|
|
|
);
|