Changeset 299af01 for src/app/api/employees/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/employees/route.ts
r057453c r299af01 3 3 import prisma from 'src/lib/prisma'; 4 4 import { authenticateRequest } from 'src/lib/auth-middleware'; 5 import { EmployeeStatus} from '@prisma/client';5 import { Prisma } from '@prisma/client'; 6 6 7 7 export async function GET(request: NextRequest) { … … 23 23 const validatedFilters = employeeTableFiltersSchema.parse(filters); 24 24 25 const employees = await prisma.employee.findMany({ 26 where: { 27 tenantId, 28 name: { contains: validatedFilters.name, mode: 'insensitive' }, 29 status: validatedFilters.status 30 ? { equals: validatedFilters.status as EmployeeStatus } 31 : undefined, 32 }, 33 }); 25 // Replace Prisma query with raw SQL 26 const employees = await prisma.$queryRaw` 27 SELECT * FROM "Employee" 28 WHERE "tenantId" = ${tenantId} 29 AND LOWER(name) LIKE LOWER(${`%${validatedFilters.name}%`}) 30 ${ 31 validatedFilters.status 32 ? Prisma.sql`AND status = ${validatedFilters.status}:::"EmployeeStatus"` 33 : Prisma.sql`AND TRUE` 34 } 35 `; 34 36 35 37 return NextResponse.json(employees);
Note:
See TracChangeset
for help on using the changeset viewer.