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 endpoint for price changes
15 let endpoint = "/buck?3=retailmax.elink.pricechange.list";
16
17 const limit = searchParams.get("limit");
18 const search = searchParams.get("search");
19 const pluList = searchParams.get("pluList");
20 const showType = searchParams.get("showType");
21
22 if (showType) {
23 endpoint += `&9=f120,0,${showType}`;
24 }
25
26 if (limit) {
27 endpoint += `&8=${limit}`;
28 }
29
30 if (search) {
31 endpoint += `&9=f101,like,${encodeURIComponent(search)}`;
32 }
33
34 if (pluList) {
35 endpoint += `&9=f100,in,${encodeURIComponent(pluList)}`;
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 price changes:", error);
47 return NextResponse.json(
48 { success: false, error: error.message || "Failed to fetch price changes" },
49 { status: error.status || 500 }
50 );
51 }
52}