2022-03-30 12:17:55 +00:00
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
2022-03-26 23:58:22 +00:00
|
|
|
|
2022-03-30 12:17:55 +00:00
|
|
|
import prisma from "@calcom/prisma";
|
2022-03-26 23:58:22 +00:00
|
|
|
|
2022-04-01 20:05:10 +00:00
|
|
|
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
|
|
|
import { AttendeesResponse } from "@lib/types";
|
|
|
|
import { schemaAttendeePublic } from "@lib/validations/attendee";
|
2022-03-26 23:58:22 +00:00
|
|
|
|
2022-04-01 20:05:10 +00:00
|
|
|
/**
|
|
|
|
* @swagger
|
|
|
|
* /api/attendees:
|
|
|
|
* get:
|
|
|
|
* summary: Get all attendees
|
|
|
|
* tags:
|
|
|
|
* - attendees
|
|
|
|
* responses:
|
|
|
|
* 200:
|
|
|
|
* description: OK
|
|
|
|
* 401:
|
|
|
|
* description: Authorization information is missing or invalid.
|
|
|
|
* 404:
|
|
|
|
* description: No attendees were found
|
|
|
|
*/
|
|
|
|
async function allAttendees(_: NextApiRequest, res: NextApiResponse<AttendeesResponse>) {
|
|
|
|
const attendees = await prisma.attendee.findMany();
|
|
|
|
const data = attendees.map((attendee) => schemaAttendeePublic.parse(attendee));
|
|
|
|
|
|
|
|
if (data) res.status(200).json({ data });
|
|
|
|
else
|
|
|
|
(error: Error) =>
|
|
|
|
res.status(404).json({
|
|
|
|
message: "No Attendees were found",
|
|
|
|
error,
|
|
|
|
});
|
2022-03-26 23:58:22 +00:00
|
|
|
}
|
2022-04-01 20:05:10 +00:00
|
|
|
|
|
|
|
export default withMiddleware("HTTP_GET")(allAttendees);
|