blob: 621297fddaebd6e5efe4e6892ff28cd9dc692444 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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)
}
|