cal.pub0.org/pages/api/webhooks/[id]/_delete.ts

46 lines
1.3 KiB
TypeScript
Raw Normal View History

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";
2022-10-19 18:26:12 +00:00
/**
* @swagger
* /webhooks/{id}:
* delete:
* summary: Remove an existing hook
* operationId: removeWebhookById
* parameters:
* - in: path
* name: id
* schema:
* type: integer
* required: true
* description: Numeric ID of the hooks to delete
* - in: query
* name: apiKey
* required: true
* schema:
* type: string
* description: Your API key
2022-10-19 18:26:12 +00:00
* tags:
* - webhooks
2022-10-19 18:26:12 +00:00
* externalDocs:
* url: https://docs.cal.com/core-features/webhooks
2022-10-19 18:26:12 +00:00
* responses:
* 201:
* description: OK, hook removed successfully
* 400:
* description: Bad request. hook id is invalid.
* 401:
* description: Authorization information is missing or invalid.
*/
export async function deleteHandler(req: NextApiRequest) {
const { prisma, query } = req;
const { id } = schemaQueryIdAsString.parse(query);
await prisma.webhook.delete({ where: { id } });
return { message: `Schedule with id: ${id} deleted successfully` };
}
export default defaultResponder(deleteHandler);