2022-03-30 12:17:55 +00:00
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
2022-03-26 00:53:56 +00:00
|
|
|
|
2022-03-30 12:17:55 +00:00
|
|
|
import prisma from "@calcom/prisma";
|
2022-03-26 00:53:56 +00:00
|
|
|
|
2022-03-29 01:59:57 +00:00
|
|
|
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
2022-03-30 14:56:24 +00:00
|
|
|
import type { TeamResponse } from "@lib/types";
|
2022-03-30 12:17:55 +00:00
|
|
|
import {
|
|
|
|
schemaQueryIdParseInt,
|
|
|
|
withValidQueryIdTransformParseInt,
|
|
|
|
} from "@lib/validations/shared/queryIdTransformParseInt";
|
2022-03-30 14:56:24 +00:00
|
|
|
import { schemaTeamPublic } from "@lib/validations/team";
|
2022-03-26 00:53:56 +00:00
|
|
|
|
2022-03-30 14:56:24 +00:00
|
|
|
/**
|
|
|
|
* @swagger
|
|
|
|
* /api/teams/:id:
|
|
|
|
* get:
|
|
|
|
* description: find team by ID
|
|
|
|
* responses:
|
|
|
|
* 200:
|
|
|
|
* description: OK
|
|
|
|
* 401:
|
|
|
|
* description: Authorization information is missing or invalid.
|
|
|
|
* 404:
|
|
|
|
* description: Team was not found
|
|
|
|
*/
|
|
|
|
export async function teamById(req: NextApiRequest, res: NextApiResponse<TeamResponse>) {
|
2022-03-29 01:59:57 +00:00
|
|
|
const safe = await schemaQueryIdParseInt.safeParse(req.query);
|
2022-03-30 12:17:55 +00:00
|
|
|
if (!safe.success) throw new Error("Invalid request query");
|
2022-03-26 00:53:56 +00:00
|
|
|
|
2022-03-30 14:56:24 +00:00
|
|
|
const team = await prisma.team.findUnique({ where: { id: safe.data.id } });
|
|
|
|
const data = schemaTeamPublic.parse(team);
|
2022-03-26 00:53:56 +00:00
|
|
|
|
2022-03-30 14:56:24 +00:00
|
|
|
if (team) res.status(200).json({ data });
|
2022-03-30 12:17:55 +00:00
|
|
|
else
|
|
|
|
(error: Error) =>
|
|
|
|
res.status(404).json({
|
|
|
|
message: "Team was not found",
|
|
|
|
error,
|
|
|
|
});
|
|
|
|
}
|
2022-03-26 00:53:56 +00:00
|
|
|
|
2022-03-30 12:17:55 +00:00
|
|
|
export default withMiddleware("HTTP_GET")(withValidQueryIdTransformParseInt(teamById));
|