diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-11-09 15:40:16 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-11-09 15:40:16 +0700 |
| commit | be0f537dc4fe384eef09436833c6407e6482c16d (patch) | |
| tree | 194b1ad3f34396cb8149075bbbd38b854aedf361 /src/app/api/stock-opname/quantity | |
| parent | 5d5401ae36e7e0c8eb38ccd943c1aa44a9573d35 (diff) | |
Initial commit
Diffstat (limited to 'src/app/api/stock-opname/quantity')
| -rw-r--r-- | src/app/api/stock-opname/quantity/route.tsx | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/app/api/stock-opname/quantity/route.tsx b/src/app/api/stock-opname/quantity/route.tsx new file mode 100644 index 0000000..621297f --- /dev/null +++ b/src/app/api/stock-opname/quantity/route.tsx @@ -0,0 +1,34 @@ +import { Credential } from "@/common/types/auth"; +import { NextRequest, NextResponse } from "next/server"; +import { prisma } from "prisma/client"; + +export async function GET(request: NextRequest) { + const credentialStr = request.cookies.get('credential')?.value + const credential: Credential | null = credentialStr ? JSON.parse(credentialStr) : null + + if (!credential) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) + + const searchParams = request.nextUrl.searchParams; + let locationId = searchParams.get('locationId'); + let productId = searchParams.get('productId'); + + if (!locationId || !productId) return NextResponse.json({ error: 'Bad Request. Missing locationId and productId' }, { status: 400 }) + let intLocationId = parseInt(locationId) + let intProductId = parseInt(productId) + + const { companyId, team } = credential + + const query = { + locationId: intLocationId, + productId: intProductId, + companyId, + team + } + + const stockOpname = await prisma.stockOpname.findFirst({ + where: query, + select: { id: true, quantity: true, user: true } + }) + + return NextResponse.json(stockOpname) +}
\ No newline at end of file |
