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 try {
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');
20
21 if (!staffId) {
22 return NextResponse.json(
23 { error: 'staffId parameter is required' },
24 { status: 400 }
25 );
26 }
27
28 const buckParams: Record<string, string> = {
29 "3": "retailmax.elink.staff.used.detail",
30 "9": `f110,0,${staffId}`,
31 };
32
33 // Add optional date filters
34 let predicateCount = 10;
35 if (fromDate) {
36 buckParams[String(predicateCount)] = `f112,ge,${fromDate}`;
37 predicateCount++;
38 }
39 if (toDate) {
40 buckParams[String(predicateCount)] = `f112,lt,${toDate}`;
41 predicateCount++;
42 }
43
44 const usedDetail = await fieldpineServerApi.buckApiCall(buckParams, authData.apiKey);
45
46 return NextResponse.json({
47 success: true,
48 data: usedDetail,
49 source: 'elink'
50 });
51
52 } catch (error) {
53 console.error('eLink staff used detail error:', error);
54 return NextResponse.json(
55 { error: 'eLink endpoint unavailable', source: 'elink' },
56 { status: 503 }
57 );
58 }
59
60 } catch (error) {
61 console.error('eLink staff used detail error:', error);
62 return NextResponse.json(
63 { error: 'Failed to fetch staff usage detail' },
64 { status: 500 }
65 );
66 }
67}