1import { NextRequest, NextResponse } from 'next/server';
2import { fieldpineServerApi } from '@/lib/server/fieldpineApi';
3import { getStoredAuth } from '@/lib/server/auth';
5export async function GET(request: NextRequest) {
7 const authData = await getStoredAuth();
8 if (!authData || !authData.authenticated) {
9 return NextResponse.json(
10 { error: 'Authentication required' },
16 const { searchParams } = new URL(request.url);
17 const staffId = searchParams.get('staffId');
18 const fromDate = searchParams.get('fromDate');
19 const toDate = searchParams.get('toDate');
21 const buckParams: Record<string, string> = {
22 "3": "retailmax.elink.staff.used.list",
25 // Add optional filters
27 buckParams["9"] = `f110,0,${staffId}`;
30 let predicateCount = 10;
32 buckParams[String(predicateCount)] = `f112,ge,${fromDate}`;
36 buckParams[String(predicateCount)] = `f112,lt,${toDate}`;
40 const usedList = await fieldpineServerApi.buckApiCall(buckParams, authData.apiKey);
42 return NextResponse.json({
49 console.error('eLink staff used list error:', error);
50 return NextResponse.json(
51 { error: 'eLink endpoint unavailable', source: 'elink' },
57 console.error('eLink staff used list error:', error);
58 return NextResponse.json(
59 { error: 'Failed to fetch staff usage' },