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 { getRequestContext } from '@/lib/server/sessionUtils';
4
5/**
6 * Today's Payment Statistics
7 * ELINK: retailmax.elink.stats.today.payment
8 * Returns payment method breakdown for today across all stores
9 */
10export async function GET(request: NextRequest) {
11 try {
12 const context = await getRequestContext(request);
13 if (!context?.session) {
14 return NextResponse.json(
15 { error: 'Authentication required' },
16 { status: 401 }
17 );
18 }
19
20 // Call Fieldpine BUCK API
21 const buckParams: Record<string, string> = {
22 "3": "retailmax.elink.stats.today.payment"
23 };
24
25 const result = await fieldpineServerApi.buckApiCall(buckParams, context.session.apiKey);
26
27 // Extract APPD array from BUCK response
28 const paymentData = result?.APPD || [];
29
30 console.log(`[Stats Today Payment] Loaded payment data for ${paymentData.length} stores`);
31
32 return NextResponse.json({
33 success: true,
34 data: paymentData,
35 source: 'elink'
36 });
37
38 } catch (error) {
39 console.error('[Stats Today Payment] Error:', error);
40 return NextResponse.json(
41 { error: 'Failed to fetch payment statistics', details: error instanceof Error ? error.message : 'Unknown error' },
42 { status: 500 }
43 );
44 }
45}