Ignore:
Timestamp:
02/27/25 00:42:38 (5 weeks ago)
Author:
Naum Shapkarovski <naumshapkarovski@…>
Branches:
main
Children:
32e9876
Parents:
3c5302a
Message:

update the seed script. update the prisma schema, use mapping

File:
1 edited

Legend:

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

    r3c5302a r87c9f1e  
    33import prisma from 'src/lib/prisma';
    44import { authenticateRequest } from 'src/lib/auth-middleware';
    5 import { CustomerStatus } from '@prisma/client';
    6 import { Prisma } from '@prisma/client';
     5import { Prisma, ClientStatus } from '@prisma/client';
    76
    87export async function GET(request: NextRequest) {
     
    2524    const validatedFilters = customerTableFiltersSchema.parse(filters);
    2625
    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    });
    3849
    3950    return NextResponse.json(customers);
     
    6071      data: {
    6172        ...validatedData,
    62         // userId,
    6373        tenantId,
    6474      },
Note: See TracChangeset for help on using the changeset viewer.