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 Control Endpoint
7 * POST /api/v1/openapi/stock2/count/control/[action]
8 * Maintain groups of stock count records (finalize, delete, etc.)
9 */
10export async function POST(
11 request: NextRequest,
12 { params }: { params: Promise<{ action: string }> }
13) {
14 try {
15 const { action } = await params;
16 const authData = await getStoredAuth();
17 if (!authData || !authData.authenticated) {
18 return NextResponse.json(
19 { error: 'Authentication required' },
20 { status: 401 }
21 );
22 }
23
24 const { searchParams } = new URL(request.url);
25 const queryParams: Record<string, string | number> = {};
26
27 const locid = searchParams.get('locid');
28 if (locid) queryParams.locid = parseInt(locid);
29
30 const pid = searchParams.get('pid');
31 if (pid) queryParams.pid = parseInt(pid);
32
33 const depid = searchParams.get('depid');
34 if (depid) queryParams.depid = parseInt(depid);
35
36 const asloc = searchParams.get('asloc');
37 if (asloc) queryParams.asloc = parseInt(asloc);
38
39 const mode = searchParams.get('mode');
40 if (mode) queryParams.mode = mode;
41
42 const result = await fieldpineServerApi.apiCall(
43 `/Stock2/Count/Control/${action}`,
44 {
45 method: 'POST',
46 params: queryParams,
47 cookie: authData.apiKey,
48 useOpenApi: true
49 }
50 );
51
52 return NextResponse.json({
53 success: true,
54 data: result,
55 source: 'openapi'
56 });
57
58 } catch (error) {
59 console.error('Stock2 Count Control error:', error);
60 return NextResponse.json(
61 { error: 'Failed to control stock counts' },
62 { status: 500 }
63 );
64 }
65}