From aaeea250bc721f0ff4c075c1c932ef2a2a066d48 Mon Sep 17 00:00:00 2001 From: Riddhesh Mahajan <40472653+riddhesh-mahajan@users.noreply.github.com> Date: Wed, 10 Jan 2024 23:56:19 +0530 Subject: [PATCH] fix: only consider unique eventTriggers (#13080) * only consider unique eventTriggers * remove intermediary const --------- Co-authored-by: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> --- apps/api/pages/api/webhooks/[id]/_patch.ts | 4 ++++ apps/api/pages/api/webhooks/_post.ts | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/apps/api/pages/api/webhooks/[id]/_patch.ts b/apps/api/pages/api/webhooks/[id]/_patch.ts index fd0f8db3f5..faba47d863 100644 --- a/apps/api/pages/api/webhooks/[id]/_patch.ts +++ b/apps/api/pages/api/webhooks/[id]/_patch.ts @@ -87,6 +87,10 @@ export async function patchHandler(req: NextApiRequest) { args.data.userId = bodyUserId; } + if (args.data.eventTriggers) { + args.data.eventTriggers = [...new Set(args.data.eventTriggers)]; + } + const result = await prisma.webhook.update(args); return { webhook: schemaWebhookReadPublic.parse(result) }; } diff --git a/apps/api/pages/api/webhooks/_post.ts b/apps/api/pages/api/webhooks/_post.ts index 8c36bcbcf6..9647a11738 100644 --- a/apps/api/pages/api/webhooks/_post.ts +++ b/apps/api/pages/api/webhooks/_post.ts @@ -87,6 +87,10 @@ async function postHandler(req: NextApiRequest) { args.data.userId = bodyUserId; } + if (args.data.eventTriggers) { + args.data.eventTriggers = [...new Set(args.data.eventTriggers)]; + } + const data = await prisma.webhook.create(args); return {