Changeset 87c9f1e for src/app/api/customers/route.ts
- Timestamp:
- 02/27/25 00:42:38 (5 weeks ago)
- Branches:
- main
- Children:
- 32e9876
- Parents:
- 3c5302a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/app/api/customers/route.ts
r3c5302a r87c9f1e 3 3 import prisma from 'src/lib/prisma'; 4 4 import { authenticateRequest } from 'src/lib/auth-middleware'; 5 import { CustomerStatus } from '@prisma/client'; 6 import { Prisma } from '@prisma/client'; 5 import { Prisma, ClientStatus } from '@prisma/client'; 7 6 8 7 export async function GET(request: NextRequest) { … … 25 24 const validatedFilters = customerTableFiltersSchema.parse(filters); 26 25 27 // Replace Prisma query with raw SQL 28 const customers = await prisma.$queryRaw` 29 SELECT * FROM "Client" 30 WHERE "tenantId" = ${tenantId} 31 AND LOWER(name) LIKE LOWER(${`%${validatedFilters.name}%`}) 32 ${ 33 validatedFilters.status 34 ? Prisma.sql`AND status = ${validatedFilters.status}::"CustomerStatus"` 35 : Prisma.sql`AND TRUE` 36 } 37 `; 26 // const customers = await prisma.$queryRaw` 27 // SELECT * FROM "Client" 28 // WHERE "tenant_id" = ${tenantId} 29 // AND LOWER(name) LIKE LOWER(${`%${validatedFilters.name}%`}) 30 // ${ 31 // validatedFilters.status 32 // ? Prisma.sql`AND status = ${validatedFilters.status}::"CustomerStatus"` 33 // : Prisma.sql`AND TRUE` 34 // } 35 // `; 36 37 const customers = await prisma.client.findMany({ 38 where: { 39 tenantId, 40 name: { 41 contains: validatedFilters.name, 42 mode: 'insensitive', 43 }, 44 ...(validatedFilters.status && { 45 status: validatedFilters.status as ClientStatus, 46 }), 47 }, 48 }); 38 49 39 50 return NextResponse.json(customers); … … 60 71 data: { 61 72 ...validatedData, 62 // userId,63 73 tenantId, 64 74 },
Note:
See TracChangeset
for help on using the changeset viewer.