The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
support search to customers
Kiran K27773bea0f1e
diff --git a/apps/web/app/api/customers/route.ts b/apps/web/app/api/customers/route.tsindex 6ae98547e4..58dc14a5b6 100644--- a/apps/web/app/api/customers/route.ts+++ b/apps/web/app/api/customers/route.ts@@ -42,7 +42,7 @@ interface CustomerResponse extends Customer {// GET /api/customers – Get all customersexport const GET = withWorkspace(async ({ workspace, searchParams }) => {- const { email, externalId, includeExpandedFields } =+ const { email, externalId, search, includeExpandedFields } =getCustomersQuerySchema.parse(searchParams);const customers = (await prisma.customer.findMany({@@ -50,6 +50,15 @@ export const GET = withWorkspace(projectId: workspace.id,...(email ? { email } : {}),...(externalId ? { externalId } : {}),+ ...(search+ ? {+ OR: [+ { email: { contains: search } },+ { name: { contains: search } },+ { externalId: { contains: search } },+ ],+ }+ : {}),},take: 100,orderBy: {diff --git a/apps/web/lib/zod/schemas/customers.ts b/apps/web/lib/zod/schemas/customers.tsindex 2d94d5d623..161b874479 100644--- a/apps/web/lib/zod/schemas/customers.ts+++ b/apps/web/lib/zod/schemas/customers.ts@@ -17,6 +17,12 @@ export const getCustomersQuerySchema = z.object({.describe("A case-sensitive filter on the list based on the customer's `externalId` field. The value must be a string.",),+ search: z+ .string()+ .optional()+ .describe(+ "A search query to filter customers by name or email or externalId.",+ ),includeExpandedFields: booleanQuerySchema.optional().describe(diff --git a/packages/prisma/schema/customer.prisma b/packages/prisma/schema/customer.prismaindex c65a57d225..edfff26497 100644--- a/packages/prisma/schema/customer.prisma+++ b/packages/prisma/schema/customer.prisma@@ -24,4 +24,5 @@ model Customer {@@unique([projectConnectId, externalId])@@index(externalId)@@index(linkId)+ @@index(email)}