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
5export async function GET(request: NextRequest) {
6 try {
7 const authData = await getStoredAuth();
8 if (!authData || !authData.authenticated) {
9 return NextResponse.json(
10 { error: 'Authentication required' },
11 { status: 401 }
12 );
13 }
14
15 const { searchParams } = new URL(request.url);
16 const limit = searchParams.get('limit') || '400';
17
18 // Query sales with status 200, 202 (awaiting picking)
19 // Fields: 2000,2001,2003,7000,905,906,907,130,131,133,902
20 const response = await fieldpineServerApi.buckApiCall({
21 '3': 'retailmax.elink.sale.list',
22 '9': 'f108,in,200,202', // Status filter
23 '10': '2000,2001,2003,7000,905,906,907,130,131,133,902', // Required fields
24 '8': limit
25 }, authData.apiKey);
26
27 const sales = response?.DATS || [];
28
29 console.log(`[Sales Picking API] Loaded ${sales.length} sales awaiting picking`);
30
31 return NextResponse.json({
32 success: true,
33 data: sales
34 });
35 } catch (error: any) {
36 console.error('[Sales Picking API] Error:', error);
37 return NextResponse.json(
38 { success: false, error: error.message || 'Failed to load picking sales' },
39 { status: 500 }
40 );
41 }
42}