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