2022-03-28 22:27:14 +00:00
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
|
2022-03-30 12:17:55 +00:00
|
|
|
import prisma from "@calcom/prisma";
|
2022-03-28 22:27:14 +00:00
|
|
|
|
2022-04-01 21:03:03 +00:00
|
|
|
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
|
|
|
import type { BaseResponse } from "@lib/types";
|
2022-03-30 12:17:55 +00:00
|
|
|
import {
|
|
|
|
schemaQueryIdParseInt,
|
|
|
|
withValidQueryIdTransformParseInt,
|
|
|
|
} from "@lib/validations/shared/queryIdTransformParseInt";
|
2022-03-28 22:27:14 +00:00
|
|
|
|
2022-04-01 21:03:03 +00:00
|
|
|
/**
|
|
|
|
* @swagger
|
|
|
|
* /api/booking-references/{id}/delete:
|
|
|
|
* delete:
|
|
|
|
* summary: Remove an existing bookingReference
|
2022-04-03 15:47:18 +00:00
|
|
|
* parameters:
|
2022-04-01 21:03:03 +00:00
|
|
|
* - in: path
|
|
|
|
* name: id
|
|
|
|
* schema:
|
|
|
|
* type: integer
|
|
|
|
* required: true
|
|
|
|
* description: Numeric ID of the bookingReference to delete
|
|
|
|
* tags:
|
2022-04-03 15:47:18 +00:00
|
|
|
* - booking-references
|
2022-04-01 21:03:03 +00:00
|
|
|
* responses:
|
|
|
|
* 201:
|
|
|
|
* description: OK, bookingReference removed successfuly
|
|
|
|
* model: BookingReference
|
|
|
|
* 400:
|
|
|
|
* description: Bad request. BookingReference id is invalid.
|
|
|
|
* 401:
|
|
|
|
* description: Authorization information is missing or invalid.
|
|
|
|
*/
|
|
|
|
export async function deleteBookingReference(req: NextApiRequest, res: NextApiResponse<BaseResponse>) {
|
|
|
|
const safe = await schemaQueryIdParseInt.safeParse(req.query);
|
|
|
|
if (!safe.success) throw new Error("Invalid request query", safe.error);
|
2022-03-28 22:27:14 +00:00
|
|
|
|
2022-04-01 21:03:03 +00:00
|
|
|
const data = await prisma.bookingReference.delete({ where: { id: safe.data.id } });
|
|
|
|
|
|
|
|
if (data)
|
|
|
|
res.status(200).json({ message: `BookingReference with id: ${safe.data.id} deleted successfully` });
|
|
|
|
else
|
|
|
|
(error: Error) =>
|
|
|
|
res.status(400).json({
|
|
|
|
message: `BookingReference with id: ${safe.data.id} was not able to be processed`,
|
|
|
|
error,
|
|
|
|
});
|
2022-03-28 22:27:14 +00:00
|
|
|
}
|
|
|
|
|
2022-04-01 21:03:03 +00:00
|
|
|
export default withMiddleware("HTTP_DELETE")(withValidQueryIdTransformParseInt(deleteBookingReference));
|