The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix include link
Steven Tey6ca88a459f7b
diff --git a/apps/web/app/api/customers/[id]/route.ts b/apps/web/app/api/customers/[id]/route.tsindex 63fedfbfbb..7642072f0d 100644--- a/apps/web/app/api/customers/[id]/route.ts+++ b/apps/web/app/api/customers/[id]/route.ts@@ -14,10 +14,15 @@ export const GET = withWorkspace(async ({ workspace, params }) => {const { id } = params;- const customer = await getCustomerOrThrow({- id,- workspaceId: workspace.id,- });+ const customer = await getCustomerOrThrow(+ {+ id,+ workspaceId: workspace.id,+ },+ {+ expand: ["link"],+ },+ );return NextResponse.json(CustomerSchema.parse(customer));},@@ -46,6 +51,9 @@ export const PATCH = withWorkspace(id,},data: { name, email, avatar, externalId },+ include: {+ link: true,+ },});return NextResponse.json(CustomerSchema.parse(customer));@@ -55,12 +63,6 @@ export const PATCH = withWorkspace(code: "conflict",message: "A customer with this external ID already exists.",});- } else if (error.code === "P2025") {- throw new DubApiError({- code: "not_found",- message:- "Customer not found. Make sure you're using the correct external ID.",- });}throw new DubApiError({@@ -84,29 +86,15 @@ export const DELETE = withWorkspace(workspaceId: workspace.id,});- try {- await prisma.customer.delete({- where: {- id,- },- });-- return NextResponse.json({+ await prisma.customer.delete({+ where: {id,- });- } catch (error) {- if (error.code === "P2025") {- throw new DubApiError({- code: "not_found",- message: "Customer not found",- });- }+ },+ });- throw new DubApiError({- code: "unprocessable_entity",- message: error.message,- });- }+ return NextResponse.json({+ id,+ });},{requiredAddOn: "conversion",diff --git a/apps/web/app/api/customers/route.ts b/apps/web/app/api/customers/route.tsindex 017c41e8b4..6d0b313d48 100644--- a/apps/web/app/api/customers/route.ts+++ b/apps/web/app/api/customers/route.ts@@ -48,6 +48,9 @@ export const POST = withWorkspace(projectId: workspace.id,projectConnectId: workspace.stripeConnectId,},+ include: {+ link: true,+ },});return NextResponse.json(CustomerSchema.parse(customer), {diff --git a/apps/web/lib/api/customers/get-customer-or-throw.ts b/apps/web/lib/api/customers/get-customer-or-throw.tsindex 66fdbb1aed..990543040e 100644--- a/apps/web/lib/api/customers/get-customer-or-throw.ts+++ b/apps/web/lib/api/customers/get-customer-or-throw.ts@@ -1,13 +1,16 @@import { prisma } from "@dub/prisma";import { DubApiError } from "../errors";-export const getCustomerOrThrow = async ({- id,- workspaceId,-}: {- id: string;- workspaceId: string;-}) => {+export const getCustomerOrThrow = async (+ {+ id,+ workspaceId,+ }: {+ id: string;+ workspaceId: string;+ },+ { expand }: { expand?: ("link" | "project")[] } = {},+) => {const customer = await prisma.customer.findUnique({where: {...(id.startsWith("ext_")@@ -20,14 +23,15 @@ export const getCustomerOrThrow = async ({: { id }),},include: {- link: true,+ link: expand?.includes("link"),},});if (!customer || customer.projectId !== workspaceId) {throw new DubApiError({code: "not_found",- message: "Customer not found.",+ message:+ "Customer not found. Make sure you're using the correct customer ID (e.g. `cus_3TagGjzRzmsFJdH8od2BNCsc`) or external ID (has to be prefixed with `ext_`).",});}