1import { NextRequest, NextResponse } from 'next/server';
2import { fieldpineServerApi } from '@/lib/server/fieldpineApi';
3import { getStoredAuth } from '@/lib/server/auth';
6 * OpenAPI Stock2 Count Endpoint
7 * GET /api/v1/openapi/stock2/count?locid=1&pid=123
8 * POST /api/v1/openapi/stock2/count - Record stock count
9 * Retrieve or record individual stock counts
11export async function GET(request: NextRequest) {
13 const authData = await getStoredAuth();
14 if (!authData || !authData.authenticated) {
15 return NextResponse.json(
16 { error: 'Authentication required' },
21 const { searchParams } = new URL(request.url);
22 const params: Record<string, string | number> = {};
24 const locid = searchParams.get('locid');
25 if (locid) params.locid = parseInt(locid);
27 const pid = searchParams.get('pid');
28 if (pid) params.pid = parseInt(pid);
30 const depid = searchParams.get('depid');
31 if (depid) params.depid = parseInt(depid);
33 const want = searchParams.get('want');
34 if (want) params.want = want;
36 const counts = await fieldpineServerApi.apiCall("/Stock2/Count", {
38 cookie: authData.apiKey,
42 return NextResponse.json({
49 console.error('Stock2 Count API error:', error);
50 return NextResponse.json(
51 { error: 'Failed to fetch stock counts' },
57export async function POST(request: NextRequest) {
59 const authData = await getStoredAuth();
60 if (!authData || !authData.authenticated) {
61 return NextResponse.json(
62 { error: 'Authentication required' },
67 const body = await request.json();
69 const result = await fieldpineServerApi.apiCall("/Stock2/Count", {
72 cookie: authData.apiKey,
76 return NextResponse.json({
83 console.error('Stock2 Count POST error:', error);
84 return NextResponse.json(
85 { error: 'Failed to record stock count' },