EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
route.ts
Go to the documentation of this file.
1import { NextRequest, NextResponse } from 'next/server';
2import { fieldpineServerApi } from '@/lib/server/fieldpineApi';
3import { getStoredAuth } from '@/lib/server/auth';
4
5/**
6 * OpenAPI Stock2 Count Summary Endpoint
7 * GET /api/v1/openapi/stock2/count-summary?locid=1&depid=5
8 * Retrieve summary of stocktake counting by location/department
9 */
10export async function GET(request: NextRequest) {
11 try {
12 const authData = await getStoredAuth();
13 if (!authData || !authData.authenticated) {
14 return NextResponse.json(
15 { error: 'Authentication required' },
16 { status: 401 }
17 );
18 }
19
20 const { searchParams } = new URL(request.url);
21 const params: Record<string, string | number> = {};
22
23 const locid = searchParams.get('locid');
24 if (locid) params.locid = parseInt(locid);
25
26 const pid = searchParams.get('pid');
27 if (pid) params.pid = parseInt(pid);
28
29 const depid = searchParams.get('depid');
30 if (depid) params.depid = parseInt(depid);
31
32 const summary = await fieldpineServerApi.apiCall("/Stock2/CountSummary", {
33 params,
34 cookie: authData.apiKey,
35 useOpenApi: true
36 });
37
38 return NextResponse.json({
39 success: true,
40 data: summary,
41 source: 'openapi'
42 });
43
44 } catch (error) {
45 console.error('Stock2 CountSummary API error:', error);
46 return NextResponse.json(
47 { error: 'Failed to fetch stock count summary' },
48 { status: 500 }
49 );
50 }
51}