Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Co-authored-by: Keith Williams <keithwillcode@gmail.com> Co-authored-by: Syed Ali Shahbaz <syedshahbaz@Syeds-MacBook-Pro.local> Co-authored-by: zomars <zomars@me.com>
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import type { Prisma } from "@prisma/client";
|
|
import type { NextApiRequest } from "next";
|
|
|
|
import { HttpError } from "@calcom/lib/http-error";
|
|
import { defaultResponder } from "@calcom/lib/server";
|
|
import prisma from "@calcom/prisma";
|
|
|
|
import { schemaAttendeeReadPublic } from "~/lib/validations/attendee";
|
|
|
|
/**
|
|
* @swagger
|
|
* /attendees:
|
|
* get:
|
|
* operationId: listAttendees
|
|
* summary: Find all attendees
|
|
* parameters:
|
|
* - in: query
|
|
* name: apiKey
|
|
* required: true
|
|
* schema:
|
|
* type: string
|
|
* description: Your API key
|
|
* tags:
|
|
* - attendees
|
|
* responses:
|
|
* 200:
|
|
* description: OK
|
|
* 401:
|
|
* description: Authorization information is missing or invalid.
|
|
* 404:
|
|
* description: No attendees were found
|
|
*/
|
|
async function handler(req: NextApiRequest) {
|
|
const { userId, isSystemWideAdmin } = req;
|
|
const args: Prisma.AttendeeFindManyArgs = isSystemWideAdmin ? {} : { where: { booking: { userId } } };
|
|
const data = await prisma.attendee.findMany(args);
|
|
const attendees = data.map((attendee) => schemaAttendeeReadPublic.parse(attendee));
|
|
if (!attendees) throw new HttpError({ statusCode: 404, message: "No attendees were found" });
|
|
return { attendees };
|
|
}
|
|
|
|
export default defaultResponder(handler);
|