cal.pub0.org/pages/api/schedules/[id]/_get.ts

39 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-10-13 20:54:38 +00:00
import type { NextApiRequest } from "next";
import { defaultResponder } from "@calcom/lib/server";
2022-11-25 13:56:58 +00:00
import { schemaSchedulePublic } from "~/lib/validations/schedule";
import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransformParseInt";
2022-10-13 20:54:38 +00:00
/**
* @swagger
* /schedules/{id}:
* get:
* operationId: getScheduleById
* summary: Find a schedule
* parameters:
* - in: path
* name: id
* schema:
* type: integer
* required: true
* description: ID of the schedule to get
* tags:
* - schedules
* responses:
* 200:
* description: OK
* 401:
* description: Authorization information is missing or invalid.
* 404:
* description: Schedule was not found
*/
export async function getHandler(req: NextApiRequest) {
const { prisma, query } = req;
const { id } = schemaQueryIdParseInt.parse(query);
const data = await prisma.schedule.findUniqueOrThrow({ where: { id }, include: { availability: true } });
return { schedule: schemaSchedulePublic.parse(data) };
}
export default defaultResponder(getHandler);