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 // Use eLink BUCK API for departments
13 const result = await fieldpineServerApi.buckApiCall({
14 "3": "retailmax.elink.departments",
15 "10": "100,101,1100" // Department fields: id, name, category
16 }, authData.apiKey!);
17
18 console.log('[Departments API] BUCK result:', {
19 hasDats: !!result.DATS,
20 datsLength: result.DATS?.length
21 });
22
23 // Return DATS array directly for franchise report compatibility
24 const departments = result.DATS || [];
25
26 return NextResponse.json(departments);
27 } catch (error: any) {
28 console.error("Error fetching departments:", error);
29 return NextResponse.json(
30 { success: false, error: error.message || "Failed to fetch departments" },
31 { status: error.status || 500 }
32 );
33 }
34}