diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-11-17 15:16:23 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-11-17 15:16:23 +0700 |
| commit | 07819844d5ef7e323fd956eacfedecb2f4f4bb80 (patch) | |
| tree | d83ba8c6ff7f47f568889ff8371ee9d9918ed166 /src/app/api/product/route.tsx | |
| parent | 10ce1ad59969576244ba786d7d17da2da3fe6f61 (diff) | |
Update result feature
Diffstat (limited to 'src/app/api/product/route.tsx')
| -rw-r--r-- | src/app/api/product/route.tsx | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/app/api/product/route.tsx b/src/app/api/product/route.tsx index 1161a4e..07ba9c7 100644 --- a/src/app/api/product/route.tsx +++ b/src/app/api/product/route.tsx @@ -1,24 +1,20 @@ +import getServerCredential from "@/common/libs/getServerCredential"; import { NextRequest, NextResponse } from "next/server"; import { prisma } from "prisma/client"; -import { Credential } from "@/common/types/auth" export async function GET(request: NextRequest) { const PAGE_SIZE = 30; const searchParams = request.nextUrl.searchParams; - const type = searchParams.get('type') 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 credentialStr = request.cookies.get('credential')?.value - const credential: Credential | null = credentialStr ? JSON.parse(credentialStr) : null + const credential = getServerCredential() - if (!credential) { - return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) - } - - const { companyId } = credential + if (!credential) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) const where = { AND: { @@ -27,7 +23,7 @@ export async function GET(request: NextRequest) { { barcode: { contains: search ?? '' } }, { itemCode: { contains: search ?? '' } }, ], - companyId: type == 'all' ? undefined : companyId + companyId: companyId ?? credential.companyId } } |
