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 * BUCK Stocktake Status Endpoint
7 * GET /api/v1/buck/stocktake/status?id=1
8 * Uses: buck?3=retailmax.elink.stocktake.status&100=1
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 id = searchParams.get('id');
22
23 if (!id) {
24 return NextResponse.json(
25 { error: 'Stocktake ID required' },
26 { status: 400 }
27 );
28 }
29
30 // Build BUCK endpoint for stocktake status
31 // buck?3=retailmax.elink.stocktake.status&100=1
32 const buckParams: Record<string, string> = {
33 '3': 'retailmax.elink.stocktake.status',
34 '100': id
35 };
36
37 const result = await fieldpineServerApi.buckApiCall(buckParams, authData.apiKey!);
38
39 return NextResponse.json({
40 success: true,
41 data: result,
42 source: 'buck-elink'
43 });
44
45 } catch (error) {
46 console.error('Stocktake status BUCK API error:', error);
47 return NextResponse.json(
48 { error: 'Failed to fetch stocktake status' },
49 { status: 500 }
50 );
51 }
52}