2022-07-08 17:21:40 +00:00
|
|
|
import type { NextApiRequest } from "next";
|
|
|
|
|
|
|
|
import { defaultResponder } from "@calcom/lib/server";
|
|
|
|
|
|
|
|
import { schemaBookingReadPublic } from "@lib/validations/booking";
|
|
|
|
import { schemaQueryIdParseInt } from "@lib/validations/shared/queryIdTransformParseInt";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
* 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);
|