summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-11-21 10:16:21 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-11-21 10:16:21 +0700
commit570b867dec4832c201e70ae8a756db70d6af4ac4 (patch)
treeb6ee17b9ced2c2b6b0e1e06373824422eac87f45 /src
parent1203dca98a712d5c0fcb8af635beea68f9ec6559 (diff)
Fix stock opname and product search where
Diffstat (limited to 'src')
-rw-r--r--src/app/api/product/route.tsx36
-rw-r--r--src/app/api/stock-opname/route.tsx11
2 files changed, 20 insertions, 27 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),
diff --git a/src/app/api/stock-opname/route.tsx b/src/app/api/stock-opname/route.tsx
index 3aa9d06..ef4e1d5 100644
--- a/src/app/api/stock-opname/route.tsx
+++ b/src/app/api/stock-opname/route.tsx
@@ -1,5 +1,5 @@
import { StockOpnameLocationRes, StockOpnameRequest } from "@/common/types/stockOpname";
-import { Team } from "@prisma/client";
+import { Prisma, Team } from "@prisma/client";
import { NextRequest, NextResponse } from "next/server";
import { prisma } from "prisma/client";
import _ from "lodash"
@@ -23,15 +23,16 @@ export async function GET(request: NextRequest) {
return NextResponse.json({ error: 'Bad Request. Missing companyId' }, { status: 400 })
}
- const where = {
+ const where: Prisma.ProductWhereInput = {
AND: {
stockOpnames: { some: {} },
companyId: parseInt(companyId),
isDifferent: show ? (show == 'diff' ? true : false) : undefined,
OR: [
- { name: { contains: search ?? '' } },
- { itemCode: { contains: search ?? '' } },
- { barcode: { contains: search ?? '' } },
+ { name: { mode: 'insensitive', contains: search ?? '' } },
+ { itemCode: { mode: 'insensitive', contains: search ?? '' } },
+ { barcode: { mode: 'insensitive', contains: search ?? '' } },
+ { stockOpnames: { some: { location: { name: { mode: 'insensitive', contains: search ?? '' } } } } },
]
}
}