2022-07-08 17:21:40 +00:00
|
|
|
import type { NextApiRequest } from "next";
|
|
|
|
|
|
|
|
import { defaultResponder } from "@calcom/lib/server";
|
|
|
|
|
2022-11-25 13:56:58 +00:00
|
|
|
import { schemaBookingReadPublic } from "~/lib/validations/booking";
|
|
|
|
import { schemaQueryIdParseInt } from "~/lib/validations/shared/queryIdTransformParseInt";
|
2022-07-08 17:21:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @swagger
|
|
|
|
* /bookings/{id}:
|
|
|
|
* get:
|
|
|
|
* summary: Find a booking
|
|
|
|
* operationId: getBookingById
|
|
|
|
* parameters:
|
|
|
|
* - in: path
|
|
|
|
* name: id
|
|
|
|
* schema:
|
|
|
|
* type: integer
|
|
|
|
* required: true
|
|
|
|
* description: ID of the booking to get
|
2023-02-07 15:41:08 +00:00
|
|
|
* - in: query
|
|
|
|
* name: apiKey
|
|
|
|
* required: true
|
|
|
|
* schema:
|
|
|
|
* type: string
|
|
|
|
* description: Your API key
|
2022-07-08 17:21:40 +00:00
|
|
|
* tags:
|
|
|
|
* - bookings
|
|
|
|
* responses:
|
|
|
|
* 200:
|
|
|
|
* description: OK
|
2022-10-19 16:03:54 +00:00
|
|
|
* content:
|
|
|
|
* application/json:
|
|
|
|
* schema:
|
|
|
|
* $ref: "#/components/schemas/Booking"
|
2022-07-08 17:21:40 +00:00
|
|
|
* 401:
|
|
|
|
* description: Authorization information is missing or invalid.
|
|
|
|
* 404:
|
|
|
|
* description: Booking was not found
|
|
|
|
*/
|
|
|
|
export async function getHandler(req: NextApiRequest) {
|
|
|
|
const { prisma, query } = req;
|
|
|
|
const { id } = schemaQueryIdParseInt.parse(query);
|
2022-10-19 18:35:34 +00:00
|
|
|
const booking = await prisma.booking.findUnique({
|
|
|
|
where: { id },
|
|
|
|
include: { attendees: true, user: true },
|
|
|
|
});
|
2022-07-08 17:21:40 +00:00
|
|
|
return { booking: schemaBookingReadPublic.parse(booking) };
|
|
|
|
}
|
|
|
|
|
|
|
|
export default defaultResponder(getHandler);
|