1import { NextRequest, NextResponse } from 'next/server';
2import { fieldpineServerApi } from '@/lib/server/fieldpineApi';
3import { getStoredAuth } from '@/lib/server/auth';
6 * OpenAPI ShelfVisits Endpoint
7 * GET /api/v1/openapi/shelf-visits - Retrieve shelf visit records
8 * POST /api/v1/openapi/shelf-visits - Record shelf visit/observation
10export async function GET(request: NextRequest) {
12 const authData = await getStoredAuth();
13 if (!authData || !authData.authenticated) {
14 return NextResponse.json(
15 { error: 'Authentication required' },
20 const { searchParams } = new URL(request.url);
21 const params: Record<string, string | number> = {};
23 const locid = searchParams.get('locid');
24 if (locid) params.locid = parseInt(locid);
26 const pid = searchParams.get('pid');
27 if (pid) params.pid = parseInt(pid);
29 const from = searchParams.get('from');
30 if (from) params.from = from;
32 const to = searchParams.get('to');
33 if (to) params.to = to;
35 const shelfVisits = await fieldpineServerApi.apiCall("/ShelfVisits", {
37 cookie: authData.apiKey,
41 return NextResponse.json({
48 console.error('ShelfVisits API error:', error);
49 return NextResponse.json(
50 { error: 'Failed to fetch shelf visits' },
56export async function POST(request: NextRequest) {
58 const authData = await getStoredAuth();
59 if (!authData || !authData.authenticated) {
60 return NextResponse.json(
61 { error: 'Authentication required' },
66 const { searchParams } = new URL(request.url);
67 const body = await request.json();
69 const params: Record<string, string> = {};
70 const cardNo = searchParams.get('CardNo');
71 if (cardNo) params.CardNo = cardNo;
73 const pass = searchParams.get('Pass');
74 if (pass) params.Pass = pass;
76 const result = await fieldpineServerApi.apiCall("/ShelfVisits", {
80 cookie: authData.apiKey,
84 return NextResponse.json({
91 console.error('ShelfVisits POST error:', error);
92 return NextResponse.json(
93 { error: 'Failed to record shelf visit' },