Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

zapier/subscribe POST + DELETE instead of separate routes (zapier/subscribe, zapier/unsubscribe)

Kiran Keab49d0c9030
diff --git a/apps/web/app/api/zapier/subscribe/route.ts b/apps/web/app/api/zapier/subscribe/route.ts
index 46911c224a..677f202eac 100644
--- a/apps/web/app/api/zapier/subscribe/route.ts
+++ b/apps/web/app/api/zapier/subscribe/route.ts
@@ -8,6 +8,10 @@ const subscribeSchema = z.object({
url: z.string(),
});
+const unsubscribeSchema = z.object({
+ id: z.string(),
+});
+
// GET /api/zapier/subscribe - Subscribe to a Zapier hook
export const POST = withWorkspace(async ({ workspace, req }) => {
const { url } = subscribeSchema.parse(await parseRequestBody(req));
@@ -31,3 +35,33 @@ export const POST = withWorkspace(async ({ workspace, req }) => {
return NextResponse.json({ id: hook.id }, { status: 201 });
});
+
+// DELETE /api/zapier/unsubscribe - Unsubscribe from a Zapier hook
+export const DELETE = withWorkspace(async ({ workspace, req }) => {
+ const { id } = unsubscribeSchema.parse(await parseRequestBody(req));
+
+ const hook = await prisma.zapierHook.delete({
+ where: {
+ projectId: workspace.id,
+ id,
+ },
+ });
+
+ // Check if there are any hooks left for the workspace
+ const hooks = await prisma.zapierHook.count({
+ where: {
+ projectId: workspace.id,
+ },
+ });
+
+ if (hooks === 0) {
+ await prisma.project.update({
+ where: { id: workspace.id },
+ data: { zapierHookEnabled: false },
+ });
+ }
+
+ console.info(`[Zapier] Workspace ${workspace.id} unsubscribed from ${hook}`);
+
+ return NextResponse.json({ status: "OK" });
+});
diff --git a/apps/web/app/api/zapier/unsubscribe/route.ts b/apps/web/app/api/zapier/unsubscribe/route.ts
deleted file mode 100644
index 1b16f90c70..0000000000
--- a/apps/web/app/api/zapier/unsubscribe/route.ts
+++ /dev/null
@@ -1,39 +0,0 @@
-import { parseRequestBody } from "@/lib/api/utils";
-import { withWorkspace } from "@/lib/auth";
-import { prisma } from "@/lib/prisma";
-import z from "@/lib/zod";
-import { NextResponse } from "next/server";
-
-const unsubscribeSchema = z.object({
- id: z.string(),
-});
-
-// POST /api/zapier/unsubscribe - Unsubscribe from a Zapier hook
-export const POST = withWorkspace(async ({ workspace, req }) => {
- const { id } = unsubscribeSchema.parse(await parseRequestBody(req));
-
- const hook = await prisma.zapierHook.delete({
- where: {
- projectId: workspace.id,
- id,
- },
- });
-
- // Check if there are any hooks left for the workspace
- const hooks = await prisma.zapierHook.count({
- where: {
- projectId: workspace.id,
- },
- });
-
- if (hooks === 0) {
- await prisma.project.update({
- where: { id: workspace.id },
- data: { zapierHookEnabled: false },
- });
- }
-
- console.info(`[Zapier] Workspace ${workspace.id} unsubscribed from ${hook}`);
-
- return NextResponse.json({ status: "OK" });
-});