From 081e942ea63637fe6bb4fcbfe4dfa16578b9a864 Mon Sep 17 00:00:00 2001 From: Steven Tey Date: Tue, 25 Feb 2025 08:39:52 -0800 Subject: [PATCH] Start moving from edge to node --- apps/web/app/api/track/sale/route.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/apps/web/app/api/track/sale/route.ts b/apps/web/app/api/track/sale/route.ts index 0197290ef..c17596f6c 100644 --- a/apps/web/app/api/track/sale/route.ts +++ b/apps/web/app/api/track/sale/route.ts @@ -3,7 +3,7 @@ import { includeTags } from "@/lib/api/links/include-tags"; import { notifyPartnerSale } from "@/lib/api/partners/notify-partner-sale"; import { calculateSaleEarnings } from "@/lib/api/sales/calculate-sale-earnings"; import { createId, parseRequestBody } from "@/lib/api/utils"; -import { withWorkspaceEdge } from "@/lib/auth/workspace-edge"; +import { withWorkspace } from "@/lib/auth"; import { getLeadEvent, recordSale } from "@/lib/tinybird"; import { redis } from "@/lib/upstash"; import { sendWorkspaceWebhookOnEdge } from "@/lib/webhook/publish-edge"; @@ -13,17 +13,15 @@ import { trackSaleRequestSchema, trackSaleResponseSchema, } from "@/lib/zod/schemas/sales"; -import { prismaEdge } from "@dub/prisma/edge"; +import { prisma } from "@dub/prisma"; import { nanoid } from "@dub/utils"; import { waitUntil } from "@vercel/functions"; import { differenceInMonths } from "date-fns"; import { NextResponse } from "next/server"; import { determinePartnerReward } from "../determine-partner-reward-edge"; -export const runtime = "edge"; - // POST /api/track/sale – Track a sale conversion event -export const POST = withWorkspaceEdge( +export const POST = withWorkspace( async ({ req, workspace }) => { const { externalId, @@ -63,7 +61,7 @@ export const POST = withWorkspaceEdge( } // Find customer - const customer = await prismaEdge.customer.findUnique({ + const customer = await prisma.customer.findUnique({ where: { projectId_externalId: { projectId: workspace.id, @@ -117,7 +115,7 @@ export const POST = withWorkspaceEdge( recordSale(saleData), // update link sales count - prismaEdge.link.update({ + prisma.link.update({ where: { id: clickData.link_id, }, @@ -132,7 +130,7 @@ export const POST = withWorkspaceEdge( include: includeTags, }), // update workspace sales usage - prismaEdge.project.update({ + prisma.project.update({ where: { id: workspace.id, }, @@ -160,7 +158,7 @@ export const POST = withWorkspaceEdge( if (typeof reward.maxDuration === "number") { // Get the first commission (earliest sale) for this customer-partner pair - const firstCommission = await prismaEdge.commission.findFirst({ + const firstCommission = await prisma.commission.findFirst({ where: { partnerId: link.partnerId, customerId: customer.id, @@ -195,7 +193,7 @@ export const POST = withWorkspaceEdge( }, }); - await prismaEdge.commission.create({ + await prisma.commission.create({ data: { id: createId({ prefix: "cm_" }), programId: link.programId, @@ -211,7 +209,7 @@ export const POST = withWorkspaceEdge( }, }); - const program = await prismaEdge.program.findUniqueOrThrow({ + const program = await prisma.program.findUniqueOrThrow({ where: { id: link.programId!, },