feat: adds automatic generation of uuid id for webhooks create on API
parent
7f42cc8479
commit
43b94d3e96
|
@ -11,7 +11,6 @@ declare module "next" {
|
||||||
userId: number;
|
userId: number;
|
||||||
method: string;
|
method: string;
|
||||||
query: { [key: string]: string | string[] };
|
query: { [key: string]: string | string[] };
|
||||||
body: any;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
import { UserPermissionRole } from "@prisma/client";
|
||||||
|
|
||||||
import prisma from "@calcom/prisma";
|
import prisma from "@calcom/prisma";
|
||||||
import { UserPermissionRole } from "@calcom/prisma/client";
|
|
||||||
|
|
||||||
export const isAdminGuard = async (userId: number) => {
|
export const isAdminGuard = async (userId: number) => {
|
||||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||||
|
|
|
@ -26,7 +26,7 @@ const schemaWebhookBaseBodyParams = Webhook.pick({
|
||||||
|
|
||||||
export const schemaWebhookCreateParams = z
|
export const schemaWebhookCreateParams = z
|
||||||
.object({
|
.object({
|
||||||
id: z.string(),
|
// id: z.string(),
|
||||||
subscriberUrl: z.string().url(),
|
subscriberUrl: z.string().url(),
|
||||||
eventTriggers: z.enum(WEBHOOK_TRIGGER_EVENTS).array(),
|
eventTriggers: z.enum(WEBHOOK_TRIGGER_EVENTS).array(),
|
||||||
active: z.boolean(),
|
active: z.boolean(),
|
||||||
|
|
|
@ -51,7 +51,7 @@ export async function WebhookById(
|
||||||
case "GET":
|
case "GET":
|
||||||
await prisma.webhook
|
await prisma.webhook
|
||||||
.findUnique({ where: { id: safeQuery.data.id } })
|
.findUnique({ where: { id: safeQuery.data.id } })
|
||||||
// .then((data) => schemaWebhookReadPublic.parse(data))
|
.then((data) => schemaWebhookReadPublic.parse(data))
|
||||||
.then((webhook) => res.status(200).json({ webhook }))
|
.then((webhook) => res.status(200).json({ webhook }))
|
||||||
.catch((error: Error) =>
|
.catch((error: Error) =>
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
|
@ -97,7 +97,7 @@ export async function WebhookById(
|
||||||
}
|
}
|
||||||
await prisma.webhook
|
await prisma.webhook
|
||||||
.update({ where: { id: safeQuery.data.id }, data: safeBody.data })
|
.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 }))
|
.then((webhook) => res.status(200).json({ webhook }))
|
||||||
.catch((error: Error) =>
|
.catch((error: Error) =>
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import type { NextApiRequest, NextApiResponse } from "next";
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
|
import { v4 as uuidv4 } from "uuid";
|
||||||
|
|
||||||
import prisma from "@calcom/prisma";
|
import prisma from "@calcom/prisma";
|
||||||
|
|
||||||
|
@ -60,7 +61,7 @@ async function createOrlistAllWebhooks(
|
||||||
res.status(400).json({ message: "Invalid request body" });
|
res.status(400).json({ message: "Invalid request body" });
|
||||||
return;
|
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" });
|
if (data) res.status(201).json({ webhook: data, message: "Webhook created successfully" });
|
||||||
else
|
else
|
||||||
(error: Error) =>
|
(error: Error) =>
|
||||||
|
|
Loading…
Reference in New Issue