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 Movements Endpoint
7 * GET /api/v1/openapi/stock2/movements?locid=1&pid=123&from=2024-01-01&to=2024-12-31
8 * Track stock movements in and out
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 from = searchParams.get('from');
30 if (from) params.from = from;
31
32 const to = searchParams.get('to');
33 if (to) params.to = to;
34
35 const detail = searchParams.get('detail');
36 if (detail) params.detail = detail;
37
38 const movements = await fieldpineServerApi.apiCall("/Stock2/Movements", {
39 params,
40 cookie: authData.apiKey,
41 useOpenApi: true
42 });
43
44 return NextResponse.json({
45 success: true,
46 data: movements,
47 source: 'openapi'
48 });
49
50 } catch (error) {
51 console.error('Stock2 Movements API error:', error);
52 return NextResponse.json(
53 { error: 'Failed to fetch stock movements' },
54 { status: 500 }
55 );
56 }
57}