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 // Get today's date in YYYYMMDD format
15 const today = new Date();
16 const dateStr = today.getFullYear() +
17 String(today.getMonth() + 1).padStart(2, '0') +
18 String(today.getDate()).padStart(2, '0');
19
20 // Use sale header search for today's sales
21 const result = await fieldpineServerApi.buckApiCall({
22 "3": "retailmax.elink.sale.header.search",
23 "100": dateStr, // From date
24 "101": dateStr, // To date
25 "f4": "1" // Include summary stats
26 }, authData.apiKey!);
27
28 console.log('[Sales Totals API] BUCK Response:', JSON.stringify(result, null, 2));
29
30 return NextResponse.json({
31 success: true,
32 data: result,
33 source: "elink",
34 });
35 } catch (error: any) {
36 console.error("Error fetching sales totals:", error);
37 return NextResponse.json(
38 { success: false, error: error.message || "Failed to fetch sales totals" },
39 { status: error.status || 500 }
40 );
41 }
42}