2022-03-30 12:17:55 +00:00
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
2022-03-28 22:27:14 +00:00
|
|
|
|
2022-03-30 12:17:55 +00:00
|
|
|
import prisma from "@calcom/prisma";
|
2022-03-28 22:27:14 +00:00
|
|
|
|
2022-03-30 14:56:24 +00:00
|
|
|
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
|
|
|
import type { SelectedCalendarResponse } from "@lib/types";
|
|
|
|
import { schemaSelectedCalendarPublic } from "@lib/validations/selected-calendar";
|
2022-03-30 12:17:55 +00:00
|
|
|
import {
|
|
|
|
schemaQueryIdParseInt,
|
|
|
|
withValidQueryIdTransformParseInt,
|
|
|
|
} from "@lib/validations/shared/queryIdTransformParseInt";
|
2022-03-28 22:27:14 +00:00
|
|
|
|
2022-03-30 14:56:24 +00:00
|
|
|
/**
|
|
|
|
* @swagger
|
|
|
|
* /api/selectedCalendars/:id:
|
|
|
|
* get:
|
|
|
|
* description: find selectedCalendar by ID
|
|
|
|
* responses:
|
|
|
|
* 200:
|
|
|
|
* description: OK
|
|
|
|
* 401:
|
|
|
|
* description: Authorization information is missing or invalid.
|
|
|
|
* 404:
|
|
|
|
* description: SelectedCalendar was not found
|
|
|
|
*/
|
|
|
|
export async function selectedCalendarById(
|
|
|
|
req: NextApiRequest,
|
|
|
|
res: NextApiResponse<SelectedCalendarResponse>
|
|
|
|
) {
|
|
|
|
const safe = await schemaQueryIdParseInt.safeParse(req.query);
|
|
|
|
if (!safe.success) throw new Error("Invalid request query");
|
2022-03-28 22:27:14 +00:00
|
|
|
|
2022-03-30 14:56:24 +00:00
|
|
|
const selectedCalendar = await prisma.selectedCalendar.findUnique({ where: { id: safe.data.id } });
|
|
|
|
const data = schemaSelectedCalendarPublic.parse(selectedCalendar);
|
2022-03-28 22:27:14 +00:00
|
|
|
|
2022-03-30 14:56:24 +00:00
|
|
|
if (selectedCalendar) res.status(200).json({ data });
|
|
|
|
else
|
|
|
|
(error: Error) =>
|
|
|
|
res.status(404).json({
|
|
|
|
message: "SelectedCalendar was not found",
|
|
|
|
error,
|
|
|
|
});
|
2022-03-28 22:27:14 +00:00
|
|
|
}
|
|
|
|
|
2022-03-30 14:56:24 +00:00
|
|
|
export default withMiddleware("HTTP_GET")(withValidQueryIdTransformParseInt(selectedCalendarById));
|