Merge pull request #105 from calcom/feat/uuid-hooks

feat: adds automatic generation of uuid id for webhooks create on API
This commit is contained in:
Agusti Fernandez Pardo
2022-06-02 15:56:01 +02:00
committed by GitHub
6 changed files with 8 additions and 6 deletions
-1
View File
@@ -11,7 +11,6 @@ declare module "next" {
userId: number;
method: string;
query: { [key: string]: string | string[] };
body: any;
}
}
+2 -1
View File
@@ -1,5 +1,6 @@
import { UserPermissionRole } from "@prisma/client";
import prisma from "@calcom/prisma";
import { UserPermissionRole } from "@calcom/prisma/client";
export const isAdminGuard = async (userId: number) => {
const user = await prisma.user.findUnique({ where: { id: userId } });
+1 -1
View File
@@ -26,7 +26,6 @@ const schemaWebhookBaseBodyParams = Webhook.pick({
export const schemaWebhookCreateParams = z
.object({
id: z.string(),
subscriberUrl: z.string().url(),
eventTriggers: z.enum(WEBHOOK_TRIGGER_EVENTS).array(),
active: z.boolean(),
@@ -52,6 +51,7 @@ export const schemaWebhookReadPublic = Webhook.pick({
eventTypeId: true,
payloadTemplate: true,
eventTriggers: true,
/** @todo: find out how to properly add back and validate those. */
// eventType: true,
// app: true,
appId: true,
+1
View File
@@ -35,6 +35,7 @@
"next-validations": "^0.2.0",
"typescript": "^4.6.4",
"tzdata": "^1.0.30",
"uuid": "^8.3.2",
"zod": "^3.16.0"
}
}
+2 -2
View File
@@ -51,7 +51,7 @@ export async function WebhookById(
case "GET":
await prisma.webhook
.findUnique({ where: { id: safeQuery.data.id } })
// .then((data) => schemaWebhookReadPublic.parse(data))
.then((data) => schemaWebhookReadPublic.parse(data))
.then((webhook) => res.status(200).json({ webhook }))
.catch((error: Error) =>
res.status(404).json({
@@ -97,7 +97,7 @@ export async function WebhookById(
}
await prisma.webhook
.update({ where: { id: safeQuery.data.id }, data: safeBody.data })
// .then((data) => schemaWebhookReadPublic.parse(data))
.then((data) => schemaWebhookReadPublic.parse(data))
.then((webhook) => res.status(200).json({ webhook }))
.catch((error: Error) =>
res.status(404).json({
+2 -1
View File
@@ -1,4 +1,5 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { v4 as uuidv4 } from "uuid";
import prisma from "@calcom/prisma";
@@ -60,7 +61,7 @@ async function createOrlistAllWebhooks(
res.status(400).json({ message: "Invalid request body" });
return;
}
const data = await prisma.webhook.create({ data: { ...safe.data, userId } });
const data = await prisma.webhook.create({ data: { id: uuidv4(), ...safe.data, userId } });
if (data) res.status(201).json({ webhook: data, message: "Webhook created successfully" });
else
(error: Error) =>