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 * Teller/Staff Performance Statistics
7 * ELINK: retailmax.elink.sale.totals.group (grouped by teller)
8 * Returns sales performance by staff member
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 const { searchParams } = new URL(request.url);
21 const startDate = searchParams.get('startDate');
22 const endDate = searchParams.get('endDate');
23 const locationId = searchParams.get('locationId');
24
25 // Build BUCK parameters for teller-grouped sales totals
26 const buckParams: Record<string, string | string[]> = {
27 "3": "retailmax.elink.sale.totals.group",
28 "10": "11000", // Request field 11000 series (quartile stats)
29 "15": "2,1,tid", // Group by teller ID
30 "13": "120", // Sort by sales amount (f120)
31 "8": "200" // Limit
32 };
33
34 // Add date filters
35 const filters: string[] = [];
36 if (startDate) {
37 filters.push(`f110,4,${startDate}`); // f110 >= startDate
38 }
39 if (endDate) {
40 filters.push(`f110,1,${endDate}`); // f110 < endDate
41 }
42 if (locationId) {
43 filters.push(`f7,0,${locationId}`); // Filter by location
44 }
45
46 if (filters.length > 0) {
47 buckParams["9"] = filters;
48 }
49
50 const result = await fieldpineServerApi.buckApiCall(buckParams, context.session.apiKey);
51
52 // Extract APPD array from BUCK response
53 const tellerData = result?.APPD || [];
54
55 console.log(`[Teller Performance] Loaded performance data for ${tellerData.length} tellers`);
56
57 return NextResponse.json({
58 success: true,
59 data: tellerData,
60 source: 'elink'
61 });
62
63 } catch (error) {
64 console.error('[Teller Performance] Error:', error);
65 return NextResponse.json(
66 { error: 'Failed to fetch teller performance', details: error instanceof Error ? error.message : 'Unknown error' },
67 { status: 500 }
68 );
69 }
70}