Add GET /teams/{id}/event-types endpoint (#251)
Allows fetching team event types - GET /event-types only lists the user event types - currently fetching the team event types isn't possible.
This commit is contained in:
@@ -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);
|
||||
@@ -0,0 +1,9 @@
|
||||
import { defaultHandler } from "@calcom/lib/server";
|
||||
|
||||
import { withMiddleware } from "~/lib/helpers/withMiddleware";
|
||||
|
||||
export default withMiddleware()(
|
||||
defaultHandler({
|
||||
GET: import("./_get"),
|
||||
})
|
||||
);
|
||||
Reference in New Issue
Block a user