Changeset 299af01 for src/app/api/customers/route.ts
- Timestamp:
- 02/26/25 14:27:26 (6 weeks ago)
- Branches:
- main
- Children:
- 3c5302a
- Parents:
- 057453c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/app/api/customers/route.ts
r057453c r299af01 4 4 import { authenticateRequest } from 'src/lib/auth-middleware'; 5 5 import { CustomerStatus } from '@prisma/client'; 6 import { Prisma } from '@prisma/client'; 6 7 7 8 export async function GET(request: NextRequest) { … … 12 13 return authResult; 13 14 } 14 const { userId } = authResult;15 const { userId, tenantId } = authResult; 15 16 16 17 const searchParams = request.nextUrl.searchParams; … … 24 25 const validatedFilters = customerTableFiltersSchema.parse(filters); 25 26 26 const customers = await prisma.client.findMany({ 27 where: { 28 name: { contains: validatedFilters.name, mode: 'insensitive' }, 29 status: validatedFilters.status 30 ? { equals: validatedFilters.status as CustomerStatus } 31 : undefined, 32 }, 33 }); 34 console.log('customers', customers); 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 `; 35 38 36 39 return NextResponse.json(customers); 37 40 } catch (error) { 41 console.error('Error fetching customers:', error); 38 42 return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 }); 39 43 } … … 47 51 return authResult; 48 52 } 49 const { userId } = authResult;53 const { userId, tenantId } = authResult; 50 54 51 55 const body = await request.json(); … … 57 61 ...validatedData, 58 62 // userId, 63 tenantId, 59 64 }, 60 65 });
Note:
See TracChangeset
for help on using the changeset viewer.