diff --git a/pages/api/teams/[teamId]/event-types/_get.ts b/pages/api/teams/[teamId]/event-types/_get.ts new file mode 100644 index 0000000000..38d1a6d425 --- /dev/null +++ b/pages/api/teams/[teamId]/event-types/_get.ts @@ -0,0 +1,65 @@ +import type { Prisma } from "@prisma/client"; +import type { NextApiRequest } from "next"; +import { z } from "zod"; + +import { defaultResponder } from "@calcom/lib/server"; + +import { schemaEventTypeReadPublic } from "~/lib/validations/event-type"; + +const querySchema = z.object({ + teamId: z.coerce.number(), +}); + +/** + * @swagger + * /teams/{teamId}/event-types: + * get: + * summary: Find all event types that belong to teamId + * operationId: listEventTypesByTeamId + * parameters: + * - in: query + * name: apiKey + * schema: + * type: string + * required: true + * description: Your API Key + * - in: path + * name: teamId + * schema: + * type: number + * required: true + * tags: + * - event-types + * externalDocs: + * url: https://docs.cal.com/core-features/event-types + * responses: + * 200: + * description: OK + * 401: + * description: Authorization information is missing or invalid. + * 404: + * description: No event types were found + */ +async function getHandler(req: NextApiRequest) { + const { userId, isAdmin, prisma } = req; + + const { teamId } = querySchema.parse(req.query); + + const args: Prisma.EventTypeFindManyArgs = { + where: { + team: isAdmin + ? { + id: teamId, + } + : { + id: teamId, + members: { some: { userId } }, + }, + }, + }; + + const data = await prisma.eventType.findMany(args); + return { event_types: data.map((attendee) => schemaEventTypeReadPublic.parse(attendee)) }; +} + +export default defaultResponder(getHandler); diff --git a/pages/api/teams/[teamId]/event-types/index.ts b/pages/api/teams/[teamId]/event-types/index.ts new file mode 100644 index 0000000000..c53e4b8ef3 --- /dev/null +++ b/pages/api/teams/[teamId]/event-types/index.ts @@ -0,0 +1,9 @@ +import { defaultHandler } from "@calcom/lib/server"; + +import { withMiddleware } from "~/lib/helpers/withMiddleware"; + +export default withMiddleware()( + defaultHandler({ + GET: import("./_get"), + }) +);