Changeset 87c9f1e for src/app/api


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

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

Location:
src/app/api
Files:
1 added
4 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      },
  • src/app/api/invoices/[id]/route.ts

    r3c5302a r87c9f1e  
    100100        data: {
    101101          invoiceNumber: validation.data.invoiceNumber,
    102           createDate: validation.data.createDate,
     102          issueDate: validation.data.issueDate,
    103103          dueDate: validation.data.dueDate,
    104104          status: validation.data.status,
  • src/app/api/invoices/route.ts

    r3c5302a r87c9f1e  
    4545          ? { equals: validatedFilters.status as InvoiceStatus }
    4646          : undefined,
    47         createDate: {
     47        issueDate: {
    4848          ...(validatedFilters.startDate && { gte: validatedFilters.startDate }),
    4949          ...(validatedFilters.endDate && { lte: validatedFilters.endDate }),
     
    108108        quantityType: validatedData.quantityType,
    109109        subTotal: validatedData.subTotal,
    110         createDate: validatedData.createDate,
     110        issueDate: validatedData.issueDate,
    111111        month: validatedData.month,
    112112        discount: validatedData.discount,
  • src/app/api/invoices/totals/route.ts

    r3c5302a r87c9f1e  
    2020    const searchParams = request.nextUrl.searchParams;
    2121    const startDate = searchParams.get('startDate')
    22       ? new Date(searchParams.get('startDate')!)
     22      ? new Date(searchParams.get('issueDate')!)
    2323      : null;
    2424
     
    3232        status,
    3333        currency,
    34         SUM("totalAmount") as total
     34        SUM("total_amount") as total
    3535      FROM "Invoice"
    36       WHERE "createDate" >= ${startDate}
    37         AND "invoiceFromId" = ${tenantId}
     36      WHERE "issue_date" >= ${startDate}
     37        AND "tenant_id" = ${tenantId}
    3838      GROUP BY status, currency
    3939    `;
Note: See TracChangeset for help on using the changeset viewer.