summaryrefslogtreecommitdiff
path: root/src/app/api/product
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/api/product')
-rw-r--r--src/app/api/product/route.tsx36
1 files changed, 14 insertions, 22 deletions
diff --git a/src/app/api/product/route.tsx b/src/app/api/product/route.tsx
index eea6162..d28a543 100644
--- a/src/app/api/product/route.tsx
+++ b/src/app/api/product/route.tsx
@@ -1,4 +1,5 @@
import getServerCredential from "@/common/libs/getServerCredential";
+import { Prisma } from "@prisma/client";
import { NextRequest, NextResponse } from "next/server";
import { prisma } from "prisma/client";
@@ -16,34 +17,25 @@ export async function GET(request: NextRequest) {
if (!credential) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
+ const where: Prisma.ProductWhereInput = {
+ AND: {
+ OR: [
+ { name: { mode: 'insensitive', contains: search ?? '' } },
+ { barcode: { mode: 'insensitive', contains: search ?? '' } },
+ { itemCode: { mode: 'insensitive', contains: search ?? '' } },
+ ],
+ companyId: companyId ?? credential.companyId
+ }
+ }
+
const products = await prisma.product.findMany({
- where: {
- AND: {
- OR: [
- { name: { mode: 'insensitive', contains: search ?? '' } },
- { barcode: { mode: 'insensitive', contains: search ?? '' } },
- { itemCode: { mode: 'insensitive', contains: search ?? '' } },
- ],
- companyId: companyId ?? credential.companyId
- }
- },
+ where,
include: { company: true },
take: PAGE_SIZE,
skip: (intPage - 1) * PAGE_SIZE
})
- const count = await prisma.product.count({
- where: {
- AND: {
- OR: [
- { name: { mode: 'insensitive', contains: search ?? '' } },
- { barcode: { mode: 'insensitive', contains: search ?? '' } },
- { itemCode: { mode: 'insensitive', contains: search ?? '' } },
- ],
- companyId: companyId ?? credential.companyId
- }
- }
- })
+ const count = await prisma.product.count({ where })
const pagination = {
page: intPage,
totalPage: Math.ceil(count / PAGE_SIZE),