Merge pull request #91 from calcom/fix/webhooks

fix: dont use schemareadpublic
pull/9078/head
Agusti Fernandez Pardo 2022-05-20 22:10:52 +02:00 committed by GitHub
commit f3ff4a8014
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 10 deletions

View File

@ -4,7 +4,7 @@ import prisma from "@calcom/prisma";
import { withMiddleware } from "@lib/helpers/withMiddleware"; import { withMiddleware } from "@lib/helpers/withMiddleware";
import { WebhookResponse, WebhooksResponse } from "@lib/types"; import { WebhookResponse, WebhooksResponse } from "@lib/types";
import { schemaWebhookCreateBodyParams, schemaWebhookReadPublic } from "@lib/validations/webhook"; import { schemaWebhookCreateBodyParams } from "@lib/validations/webhook";
async function createOrlistAllWebhooks( async function createOrlistAllWebhooks(
{ method, body, userId }: NextApiRequest, { method, body, userId }: NextApiRequest,
@ -29,13 +29,13 @@ async function createOrlistAllWebhooks(
* 404: * 404:
* description: No webhooks were found * description: No webhooks were found
*/ */
await prisma.webhook const webhooks = await prisma.webhook
.findMany({ where: { userId } }) .findMany({ where: { userId } })
.then((data) => res.status(200).json({ webhooks: data })) .catch((error) => console.log(error));
.catch((error) => { if (!webhooks) {
console.log(error); console.log();
res.status(404).json({ message: "No webhooks were found", error }); res.status(404).json({ message: "No webhooks were found" });
}); } else res.status(200).json({ webhooks });
} else if (method === "POST") { } else if (method === "POST") {
/** /**
* @swagger * @swagger
@ -62,9 +62,7 @@ async function createOrlistAllWebhooks(
} }
const data = await prisma.webhook.create({ data: { ...safe.data, userId } }); const data = await prisma.webhook.create({ data: { ...safe.data, userId } });
const webhook = schemaWebhookReadPublic.parse(data); if (data) res.status(201).json({ webhook: data, message: "Webhook created successfully" });
if (data) res.status(201).json({ webhook, message: "Webhook created successfully" });
else else
(error: Error) => (error: Error) =>
res.status(400).json({ res.status(400).json({