From ae3207e9778c3f2fb01d64714ff15fc073ec093d Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Fri, 1 Dec 2023 10:16:12 +0700
Subject: Update compute different, result, and product list feature

---
 src/app/api/product/route.tsx | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

(limited to 'src/app/api/product/route.tsx')

diff --git a/src/app/api/product/route.tsx b/src/app/api/product/route.tsx
index 63813aa..de8a482 100644
--- a/src/app/api/product/route.tsx
+++ b/src/app/api/product/route.tsx
@@ -8,11 +8,15 @@ export async function GET(request: NextRequest) {
 
   const searchParams = request.nextUrl.searchParams;
   const search = searchParams.get('search');
+
   const page = searchParams.get('page');
   const intPage: number = page ? parseInt(page) : 1;
+
   const paramCompanyId = searchParams.get('companyId')
   const companyId = paramCompanyId ? parseInt(paramCompanyId) : null
 
+  const show = searchParams.get('show')
+
   const credential = getServerCredential()
 
   if (!credential) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
@@ -24,8 +28,10 @@ export async function GET(request: NextRequest) {
         { barcode: { mode: 'insensitive', contains: search ?? '' } },
         { itemCode: { mode: 'insensitive', contains: search ?? '' } },
       ],
-      companyId: companyId ?? credential.companyId
-    }
+      companyId: companyId ?? credential.companyId,
+      stockOpnames: { none: show === 'not-count' ? {} : undefined },
+      onhandQty: { gt: show === 'not-count' ? 0 : undefined },
+    },
   }
 
   const products = await prisma.product.findMany({
@@ -40,6 +46,7 @@ export async function GET(request: NextRequest) {
   const pagination = {
     page: intPage,
     totalPage: Math.ceil(count / PAGE_SIZE),
+    count
   }
 
   return NextResponse.json({ products, ...pagination })
-- 
cgit v1.2.3

