summaryrefslogtreecommitdiff
path: root/src/app
diff options
context:
space:
mode:
Diffstat (limited to 'src/app')
-rw-r--r--src/app/api/location/route.tsx2
-rw-r--r--src/app/api/product/route.tsx40
2 files changed, 27 insertions, 15 deletions
diff --git a/src/app/api/location/route.tsx b/src/app/api/location/route.tsx
index bc4cfff..7139c6d 100644
--- a/src/app/api/location/route.tsx
+++ b/src/app/api/location/route.tsx
@@ -15,7 +15,7 @@ export async function GET(request: NextRequest) {
const locations = await prisma.location.findMany({
where: {
companyId,
- name: { contains: search ?? '' }
+ name: { mode: 'insensitive', contains: search ?? '' }
},
take: 20
})
diff --git a/src/app/api/product/route.tsx b/src/app/api/product/route.tsx
index 07ba9c7..eea6162 100644
--- a/src/app/api/product/route.tsx
+++ b/src/app/api/product/route.tsx
@@ -16,29 +16,41 @@ export async function GET(request: NextRequest) {
if (!credential) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
- const where = {
- AND: {
- OR: [
- { name: { contains: search ?? '' } },
- { barcode: { contains: search ?? '' } },
- { itemCode: { contains: search ?? '' } },
- ],
- companyId: companyId ?? credential.companyId
- }
- }
-
const products = await prisma.product.findMany({
- where,
+ where: {
+ AND: {
+ OR: [
+ { name: { mode: 'insensitive', contains: search ?? '' } },
+ { barcode: { mode: 'insensitive', contains: search ?? '' } },
+ { itemCode: { mode: 'insensitive', contains: search ?? '' } },
+ ],
+ companyId: companyId ?? credential.companyId
+ }
+ },
include: { company: true },
take: PAGE_SIZE,
skip: (intPage - 1) * PAGE_SIZE
})
- const count = await prisma.product.count({ where })
+ 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 pagination = {
page: intPage,
totalPage: Math.ceil(count / PAGE_SIZE),
}
return NextResponse.json({ products, ...pagination })
-} \ No newline at end of file
+}
+
+// TODO: Search case sensitive
+// TODO: Submit harus di done \ No newline at end of file