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');
22 return NextResponse.json(
23 { error: 'staffId parameter is required' },
28 const buckParams: Record<string, string> = {
29 "3": "retailmax.elink.staff.used.detail",
30 "9": `f110,0,${staffId}`,
33 // Add optional date filters
34 let predicateCount = 10;
36 buckParams[String(predicateCount)] = `f112,ge,${fromDate}`;
40 buckParams[String(predicateCount)] = `f112,lt,${toDate}`;
44 const usedDetail = await fieldpineServerApi.buckApiCall(buckParams, authData.apiKey);
46 return NextResponse.json({
53 console.error('eLink staff used detail error:', error);
54 return NextResponse.json(
55 { error: 'eLink endpoint unavailable', source: 'elink' },
61 console.error('eLink staff used detail error:', error);
62 return NextResponse.json(
63 { error: 'Failed to fetch staff usage detail' },