Ignore:
Timestamp:
02/26/25 14:27:26 (6 weeks ago)
Author:
Naum Shapkarovski <naumshapkarovski@…>
Branches:
main
Children:
3c5302a
Parents:
057453c
Message:

chore

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/app/api/employees/route.ts

    r057453c r299af01  
    33import prisma from 'src/lib/prisma';
    44import { authenticateRequest } from 'src/lib/auth-middleware';
    5 import { EmployeeStatus } from '@prisma/client';
     5import { Prisma } from '@prisma/client';
    66
    77export async function GET(request: NextRequest) {
     
    2323    const validatedFilters = employeeTableFiltersSchema.parse(filters);
    2424
    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    `;
    3436
    3537    return NextResponse.json(employees);
Note: See TracChangeset for help on using the changeset viewer.