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) {
9 return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
10 }
11
12 const { searchParams } = new URL(request.url);
13
14 // Build BUCK endpoint for account financial data
15 let endpoint = "/buck?3=retailmax.elink.account.financial&9=f100,4,0&10=1003";
16
17 const limit = searchParams.get("limit");
18 const search = searchParams.get("search");
19 const showZeroBalance = searchParams.get("showZeroBalance") === "true";
20 const showRetired = searchParams.get("showRetired") === "true";
21
22 if (limit) {
23 endpoint += `&8=${limit}`;
24 }
25
26 if (search) {
27 endpoint += `&9=f101,like,${encodeURIComponent(search)}`;
28 }
29
30 if (!showZeroBalance) {
31 endpoint += "&9=f114,5,0";
32 }
33
34 if (showRetired) {
35 endpoint += "&9=f147,0,1";
36 }
37
38 const result = await fieldpineServerApi.buckApiCall(endpoint, authData.apiKey!);
39
40 return NextResponse.json({
41 success: true,
42 data: result.DATS || [],
43 source: "elink",
44 });
45 } catch (error: any) {
46 console.error("Error fetching account financial data:", error);
47 return NextResponse.json(
48 { success: false, error: error.message || "Failed to fetch account financial data" },
49 { status: error.status || 500 }
50 );
51 }
52}