cal.pub0.org/pages/api/destination-calendars/index.ts

43 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-03-30 12:17:55 +00:00
import type { NextApiRequest, NextApiResponse } from "next";
2022-03-30 12:17:55 +00:00
import prisma from "@calcom/prisma";
2022-04-01 23:55:41 +00:00
import { withMiddleware } from "@lib/helpers/withMiddleware";
import { DestinationCalendarsResponse } from "@lib/types";
import { schemaDestinationCalendarPublic } from "@lib/validations/destination-calendar";
/**
* @swagger
* /api/destination-calendars:
* get:
* summary: Get all destinationCalendars
* tags:
* - destination-calendars
2022-04-01 23:55:41 +00:00
* responses:
* 200:
* description: OK
* 401:
* description: Authorization information is missing or invalid.
* 404:
* description: No destinationCalendars were found
*/
async function allDestinationCalendars(
_: NextApiRequest,
res: NextApiResponse<DestinationCalendarsResponse>
) {
const destinationCalendars = await prisma.destinationCalendar.findMany();
const data = destinationCalendars.map((destinationCalendar) =>
schemaDestinationCalendarPublic.parse(destinationCalendar)
);
if (data) res.status(200).json({ data });
2022-04-01 23:55:41 +00:00
else
(error: Error) =>
res.status(404).json({
message: "No DestinationCalendars were found",
error,
});
}
2022-04-01 23:55:41 +00:00
export default withMiddleware("HTTP_GET")(allDestinationCalendars);