The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
externalId -> id
Kiran K4e88b67beee7
diff --git a/apps/web/app/api/customers/[id]/route.ts b/apps/web/app/api/customers/[id]/route.tsindex 658f3fc5ed..c4b574d211 100644--- a/apps/web/app/api/customers/[id]/route.ts+++ b/apps/web/app/api/customers/[id]/route.ts@@ -8,17 +8,15 @@ import {} from "@/lib/zod/schemas/customers";import { NextResponse } from "next/server";-// GET /api/customers/:id – Get a customer by external ID+// GET /api/customers/:id – Get a customer by IDexport const GET = withWorkspace(async ({ workspace, params }) => {- const { id: externalId } = params;+ const { id } = params;const customer = await prisma.customer.findUnique({where: {- projectId_externalId: {- projectId: workspace.id,- externalId,- },+ id,+ projectId: workspace.id,},});@@ -36,27 +34,22 @@ export const GET = withWorkspace(},);-// PATCH /api/customers/:id – Update a customer by external ID+// PATCH /api/customers/:id – Update a customer by IDexport const PATCH = withWorkspace(async ({ workspace, params, req }) => {- const { id: externalId } = params;+ const { id } = params;- const {- externalId: newExternalId,- name,- email,- avatar,- } = updateCustomerBodySchema.parse(await parseRequestBody(req));+ const { externalId, name, email, avatar } = updateCustomerBodySchema.parse(+ await parseRequestBody(req),+ );try {const customer = await prisma.customer.update({where: {- projectId_externalId: {- projectId: workspace.id,- externalId,- },+ id,+ projectId: workspace.id,},- data: { name, email, avatar, externalId: newExternalId },+ data: { name, email, avatar, externalId },});return NextResponse.json(CustomerSchema.parse(customer));@@ -85,23 +78,21 @@ export const PATCH = withWorkspace(},);-// DELETE /api/customers/:id – Delete a customer by external ID+// DELETE /api/customers/:id – Delete a customer by IDexport const DELETE = withWorkspace(async ({ workspace, params }) => {- const { id: externalId } = params;+ const { id } = params;try {await prisma.customer.delete({where: {- projectId_externalId: {- projectId: workspace.id,- externalId,- },+ id,+ projectId: workspace.id,},});return NextResponse.json({- externalId,+ id,});} catch (error) {if (error.code === "P2025") {diff --git a/apps/web/lib/openapi/customers/delete-customer.ts b/apps/web/lib/openapi/customers/delete-customer.tsindex f4dfa97746..f9a5ebed58 100644--- a/apps/web/lib/openapi/customers/delete-customer.ts+++ b/apps/web/lib/openapi/customers/delete-customer.ts@@ -9,14 +9,14 @@ export const deleteCustomer: ZodOpenApiOperationObject = {summary: "Delete a customer",description: "Delete a customer from a workspace.",requestParams: {- path: CustomerSchema.pick({ externalId: true }),+ path: CustomerSchema.pick({ id: true }),},responses: {"200": {description: "The customer was deleted.",content: {"application/json": {- schema: CustomerSchema.pick({ externalId: true }),+ schema: CustomerSchema.pick({ id: true }),},},},diff --git a/apps/web/lib/openapi/customers/get-customer.ts b/apps/web/lib/openapi/customers/get-customer.tsindex 42254c8202..90520a872e 100644--- a/apps/web/lib/openapi/customers/get-customer.ts+++ b/apps/web/lib/openapi/customers/get-customer.ts@@ -6,9 +6,9 @@ export const getCustomer: ZodOpenApiOperationObject = {operationId: "getCustomer","x-speakeasy-name-override": "get",summary: "Get a customer",- description: "Get a customer by externalID for the authenticated workspace.",+ description: "Get a customer by ID for the authenticated workspace.",requestParams: {- path: CustomerSchema.pick({ externalId: true }),+ path: CustomerSchema.pick({ id: true }),},responses: {"200": {diff --git a/apps/web/lib/openapi/customers/update-customer.ts b/apps/web/lib/openapi/customers/update-customer.tsindex 64ee8f9841..5e02dde2a9 100644--- a/apps/web/lib/openapi/customers/update-customer.ts+++ b/apps/web/lib/openapi/customers/update-customer.ts@@ -12,7 +12,7 @@ export const updateCustomer: ZodOpenApiOperationObject = {summary: "Update a customer",description: "Update a customer for the authenticated workspace.",requestParams: {- path: CustomerSchema.pick({ externalId: true }),+ path: CustomerSchema.pick({ id: true }),},requestBody: {content: {diff --git a/apps/web/tests/customers/index.test.ts b/apps/web/tests/customers/index.test.tsindex 09702fb031..2e8ccb6696 100644--- a/apps/web/tests/customers/index.test.ts+++ b/apps/web/tests/customers/index.test.ts@@ -25,8 +25,10 @@ describe.sequential("/customers/**", async () => {const h = new IntegrationHarness();const { http } = await h.init();+ let customerId: string;+afterAll(async () => {- await h.deleteCustomer(customerRecord.externalId);+ await h.deleteCustomer(customerId);});test("POST /customers", async () => {@@ -37,11 +39,13 @@ describe.sequential("/customers/**", async () => {expect(status).toEqual(201);expect(customer).toStrictEqual(expectedCustomer);++ customerId = customer.id;});- test("GET /customers/{externalId}", async () => {+ test("GET /customers/{id}", async () => {const { status, data: customer } = await http.get<Customer>({- path: `/customers/${customerRecord.externalId}`,+ path: `/customers/${customerId}`,});expect(status).toEqual(200);@@ -62,13 +66,13 @@ describe.sequential("/customers/**", async () => {expect(customerFound).toStrictEqual(expectedCustomer);});- test("PATCH /customers/{externalId}", async () => {+ test("PATCH /customers/{id}", async () => {const toUpdate = {email: `${externalId}@example.co`,};const { status, data: customer } = await http.patch<Customer>({- path: `/customers/${customerRecord.externalId}`,+ path: `/customers/${customerId}`,body: toUpdate,});@@ -79,12 +83,12 @@ describe.sequential("/customers/**", async () => {});});- test("DELETE /customers/{externalId}", async () => {+ test("DELETE /customers/{id}", async () => {const { status, data } = await http.delete({- path: `/customers/${customerRecord.externalId}`,+ path: `/customers/${customerId}`,});expect(status).toEqual(200);- expect(data).toEqual({ externalId: customerRecord.externalId });+ expect(data).toEqual({ id: customerId });});});diff --git a/apps/web/tests/utils/integration.ts b/apps/web/tests/utils/integration.tsindex 610807e729..cdf1e65b7e 100644--- a/apps/web/tests/utils/integration.ts+++ b/apps/web/tests/utils/integration.ts@@ -75,9 +75,9 @@ export class IntegrationHarness {}// Delete customer- public async deleteCustomer(externalId: string) {+ public async deleteCustomer(id: string) {await this.http.delete({- path: `/customers/${externalId}`,+ path: `/customers/${id}`,});}}