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-29 01:59:57 +00:00
|
|
|
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
2022-03-30 14:56:24 +00:00
|
|
|
import { TeamsResponse } from "@lib/types";
|
|
|
|
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:
|
|
|
|
* get:
|
2022-03-31 20:14:37 +00:00
|
|
|
* summary: Returns all teams
|
|
|
|
* tags:
|
|
|
|
* - teams
|
2022-03-30 14:56:24 +00:00
|
|
|
* responses:
|
|
|
|
* 200:
|
|
|
|
* description: OK
|
|
|
|
* 401:
|
|
|
|
* description: Authorization information is missing or invalid.
|
|
|
|
* 404:
|
|
|
|
* description: No teams were found
|
|
|
|
*/
|
|
|
|
async function allTeams(_: NextApiRequest, res: NextApiResponse<TeamsResponse>) {
|
|
|
|
const teams = await prisma.team.findMany();
|
|
|
|
const data = teams.map((team) => schemaTeamPublic.parse(team));
|
2022-03-29 01:59:57 +00:00
|
|
|
|
|
|
|
if (data) res.status(200).json({ data });
|
2022-03-30 12:17:55 +00:00
|
|
|
else
|
|
|
|
(error: Error) =>
|
2022-03-30 14:56:24 +00:00
|
|
|
res.status(404).json({
|
2022-03-30 12:17:55 +00:00
|
|
|
message: "No Teams were found",
|
|
|
|
error,
|
|
|
|
});
|
2022-03-26 00:53:56 +00:00
|
|
|
}
|
2022-03-29 01:59:57 +00:00
|
|
|
|
2022-03-30 12:17:55 +00:00
|
|
|
export default withMiddleware("HTTP_GET")(allTeams);
|