The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
update customer object
Kiran K70b952d1d728
diff --git a/apps/web/app/api/customers/[id]/route.ts b/apps/web/app/api/customers/[id]/route.tsindex f9883ec178..ec312bdc72 100644--- a/apps/web/app/api/customers/[id]/route.ts+++ b/apps/web/app/api/customers/[id]/route.ts@@ -12,6 +12,7 @@ import { NextResponse } from "next/server";export const GET = withWorkspace(async ({ workspace, params }) => {const { id: externalId } = params;+const customer = await prisma.customer.findUnique({where: {projectId_externalId: {@@ -20,6 +21,7 @@ export const GET = withWorkspace(},},});+if (!customer) {throw new DubApiError({code: "not_found",@@ -27,12 +29,7 @@ export const GET = withWorkspace(});}- return NextResponse.json(- CustomerSchema.parse({- ...customer,- id: customer.externalId,- }),- );+ return NextResponse.json(CustomerSchema.parse(customer));},{requiredAddOn: "conversion",@@ -43,6 +40,7 @@ export const GET = withWorkspace(export const PATCH = withWorkspace(async ({ workspace, params, req }) => {const { id: externalId } = params;+const {id: newExternalId,name,@@ -61,12 +59,7 @@ export const PATCH = withWorkspace(data: { name, email, avatar, externalId: newExternalId },});- return NextResponse.json(- CustomerSchema.parse({- ...customer,- id: customer.externalId,- }),- );+ return NextResponse.json(CustomerSchema.parse(customer));} catch (error) {if (error.code === "P2002") {throw new DubApiError({@@ -76,7 +69,8 @@ export const PATCH = withWorkspace(} else if (error.code === "P2025") {throw new DubApiError({code: "not_found",- message: "Customer not found",+ message:+ "Customer not found. Make sure you're using the correct external ID.",});}@@ -95,6 +89,7 @@ export const PATCH = withWorkspace(export const DELETE = withWorkspace(async ({ workspace, params }) => {const { id: externalId } = params;+try {const customer = await prisma.customer.delete({where: {diff --git a/apps/web/app/api/customers/route.ts b/apps/web/app/api/customers/route.tsindex a0acbca7bb..8b27933b0e 100644--- a/apps/web/app/api/customers/route.ts+++ b/apps/web/app/api/customers/route.ts@@ -22,12 +22,7 @@ export const GET = withWorkspace(},});- return NextResponse.json(- customers.map((customer) => ({- ...customer,- id: customer.externalId,- })),- );+ return NextResponse.json(CustomerSchema.array().parse(customers));},{requiredAddOn: "conversion",@@ -55,9 +50,7 @@ export const POST = withWorkspace(},});- return NextResponse.json(- CustomerSchema.parse({ ...customer, id: customer.externalId }),- );+ return NextResponse.json(CustomerSchema.parse(customer));} catch (error) {if (error.code === "P2002") {throw new DubApiError({diff --git a/apps/web/lib/zod/schemas/customers.ts b/apps/web/lib/zod/schemas/customers.tsindex d1018415f6..6754274de5 100644--- a/apps/web/lib/zod/schemas/customers.ts+++ b/apps/web/lib/zod/schemas/customers.ts@@ -19,17 +19,22 @@ export const createCustomerBodySchema = z.object({.string().url().nullish()- .describe("Avatar of the customer in the client's app."),+ .describe("Avatar URL of the customer in the client's app."),});export const updateCustomerBodySchema = createCustomerBodySchema.partial();// customer object schemaexport const CustomerSchema = z.object({- id: z.string(),- name: z.string(),- email: z.string().nullish(),- avatar: z.string().nullish(),+ id: z.string().describe("The unique identifier of the customer in Dub."),+ externalId: z+ .string()+ .nullish()+ .describe("Unique identifier for the customer in the client's app."),+ name: z.string().describe("Name of the customer."),+ email: z.string().nullish().describe("Email of the customer."),+ avatar: z.string().nullish().describe("Avatar URL of the customer."),+ createdAt: z.date().describe("The date the customer was created."),});export const trackCustomerRequestSchema = z.object({