cal.pub0.org/pages/api/custom-inputs/_get.ts

31 lines
1006 B
TypeScript
Raw Normal View History

import type { Prisma } from "@prisma/client";
import type { NextApiRequest } from "next";
import { defaultResponder } from "@calcom/lib/server";
2022-11-25 13:56:58 +00:00
import { schemaEventTypeCustomInputPublic } from "~/lib/validations/event-type-custom-input";
/**
* @swagger
* /custom-inputs:
* get:
* summary: Find all eventTypeCustomInputs
* tags:
* - custom-inputs
* responses:
* 200:
* description: OK
* 401:
* description: Authorization information is missing or invalid.
* 404:
* description: No eventTypeCustomInputs were found
*/
async function getHandler(req: NextApiRequest) {
const { userId, isAdmin, prisma } = req;
const args: Prisma.EventTypeCustomInputFindManyArgs = isAdmin ? {} : { where: { eventType: { userId } } };
const data = await prisma.eventTypeCustomInput.findMany(args);
return { event_type_custom_inputs: data.map((v) => schemaEventTypeCustomInputPublic.parse(v)) };
}
export default defaultResponder(getHandler);