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 Stocktakes Endpoint
7 * GET /api/v1/openapi/stocktakes?location=1&state=current
8 * List defined stocktakes
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 location = searchParams.get('location');
24 if (location) params.location = parseInt(location);
25
26 const state = searchParams.get('state');
27 if (state) params.state = state;
28
29 const stocktakes = await fieldpineServerApi.apiCall("/Stocktakes", {
30 params,
31 cookie: authData.apiKey,
32 useOpenApi: true
33 });
34
35 return NextResponse.json({
36 success: true,
37 data: stocktakes,
38 source: 'openapi'
39 });
40
41 } catch (error) {
42 console.error('Stocktakes API error:', error);
43 return NextResponse.json(
44 { error: 'Failed to fetch stocktakes' },
45 { status: 500 }
46 );
47 }
48}