2022-10-19 18:26:12 +00:00
|
|
|
import type { NextApiRequest } from "next";
|
|
|
|
|
|
|
|
import { defaultResponder } from "@calcom/lib/server";
|
|
|
|
|
2022-11-25 13:56:58 +00:00
|
|
|
import { schemaQueryIdAsString } from "~/lib/validations/shared/queryIdString";
|
|
|
|
import { schemaWebhookReadPublic } from "~/lib/validations/webhook";
|
2022-10-19 18:26:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @swagger
|
|
|
|
* /webhooks/{id}:
|
|
|
|
* get:
|
|
|
|
* summary: Find a webhook
|
|
|
|
* operationId: getWebhookById
|
|
|
|
* parameters:
|
|
|
|
* - in: path
|
|
|
|
* name: id
|
|
|
|
* schema:
|
|
|
|
* type: integer
|
|
|
|
* required: true
|
|
|
|
* description: Numeric ID of the webhook to get
|
2023-03-10 17:03:09 +00:00
|
|
|
* - in: query
|
|
|
|
* name: apiKey
|
|
|
|
* required: true
|
|
|
|
* schema:
|
|
|
|
* type: string
|
|
|
|
* description: Your API key
|
2022-10-19 18:26:12 +00:00
|
|
|
* tags:
|
2023-03-10 17:03:09 +00:00
|
|
|
* - webhooks
|
2022-10-19 18:26:12 +00:00
|
|
|
* externalDocs:
|
2023-03-10 17:03:09 +00:00
|
|
|
* url: https://docs.cal.com/core-features/webhooks
|
2022-10-19 18:26:12 +00:00
|
|
|
* responses:
|
|
|
|
* 200:
|
|
|
|
* description: OK
|
|
|
|
* 401:
|
|
|
|
* description: Authorization information is missing or invalid.
|
|
|
|
* 404:
|
|
|
|
* description: Webhook was not found
|
|
|
|
*/
|
|
|
|
export async function getHandler(req: NextApiRequest) {
|
|
|
|
const { prisma, query } = req;
|
|
|
|
const { id } = schemaQueryIdAsString.parse(query);
|
|
|
|
const data = await prisma.webhook.findUniqueOrThrow({ where: { id } });
|
|
|
|
return { webhook: schemaWebhookReadPublic.parse(data) };
|
|
|
|
}
|
|
|
|
|
|
|
|
export default defaultResponder(getHandler);
|