Changeset 87c9f1e for src/app/api
- Timestamp:
- 02/27/25 00:42:38 (6 weeks ago)
- Branches:
- main
- Children:
- 32e9876
- Parents:
- 3c5302a
- Location:
- src/app/api
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/app/api/customers/route.ts
r3c5302a r87c9f1e 3 3 import prisma from 'src/lib/prisma'; 4 4 import { authenticateRequest } from 'src/lib/auth-middleware'; 5 import { CustomerStatus } from '@prisma/client'; 6 import { Prisma } from '@prisma/client'; 5 import { Prisma, ClientStatus } from '@prisma/client'; 7 6 8 7 export async function GET(request: NextRequest) { … … 25 24 const validatedFilters = customerTableFiltersSchema.parse(filters); 26 25 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 }); 38 49 39 50 return NextResponse.json(customers); … … 60 71 data: { 61 72 ...validatedData, 62 // userId,63 73 tenantId, 64 74 }, -
src/app/api/invoices/[id]/route.ts
r3c5302a r87c9f1e 100 100 data: { 101 101 invoiceNumber: validation.data.invoiceNumber, 102 createDate: validation.data.createDate,102 issueDate: validation.data.issueDate, 103 103 dueDate: validation.data.dueDate, 104 104 status: validation.data.status, -
src/app/api/invoices/route.ts
r3c5302a r87c9f1e 45 45 ? { equals: validatedFilters.status as InvoiceStatus } 46 46 : undefined, 47 createDate: {47 issueDate: { 48 48 ...(validatedFilters.startDate && { gte: validatedFilters.startDate }), 49 49 ...(validatedFilters.endDate && { lte: validatedFilters.endDate }), … … 108 108 quantityType: validatedData.quantityType, 109 109 subTotal: validatedData.subTotal, 110 createDate: validatedData.createDate,110 issueDate: validatedData.issueDate, 111 111 month: validatedData.month, 112 112 discount: validatedData.discount, -
src/app/api/invoices/totals/route.ts
r3c5302a r87c9f1e 20 20 const searchParams = request.nextUrl.searchParams; 21 21 const startDate = searchParams.get('startDate') 22 ? new Date(searchParams.get(' startDate')!)22 ? new Date(searchParams.get('issueDate')!) 23 23 : null; 24 24 … … 32 32 status, 33 33 currency, 34 SUM("total Amount") as total34 SUM("total_amount") as total 35 35 FROM "Invoice" 36 WHERE " createDate" >= ${startDate}37 AND " invoiceFromId" = ${tenantId}36 WHERE "issue_date" >= ${startDate} 37 AND "tenant_id" = ${tenantId} 38 38 GROUP BY status, currency 39 39 `;
Note:
See TracChangeset
for help on using the changeset viewer.