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 sale list
15 let endpoint = "/buck?3=retailmax.elink.sale.list";
16
17 // Add all filters from query parameters
18 const filters = searchParams.getAll("filter");
19 const limit = searchParams.get("limit");
20 const fields = searchParams.get("fields");
21
22 if (fields) endpoint += `&10=${fields}`;
23 if (limit) endpoint += `&8=${limit}`;
24
25 // Add filters (field predicates)
26 for (const filter of filters) {
27 endpoint += `&9=${filter}`;
28 }
29
30 const result = await fieldpineServerApi.buckApiCall(endpoint, authData.apiKey!);
31
32 return NextResponse.json({
33 success: true,
34 data: result,
35 source: "elink",
36 });
37 } catch (error: any) {
38 console.error("Error fetching sales list:", error);
39 return NextResponse.json(
40 { success: false, error: error.message || "Failed to fetch sales list" },
41 { status: error.status || 500 }
42 );
43 }
44}