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
5/**
6 * Departments API Endpoint
7 * Fetches department list from Fieldpine
8 */
9export async function GET(request: NextRequest) {
10 try {
11 // Verify authentication
12 const authData = await getStoredAuth();
13 if (!authData || !authData.authenticated) {
14 return NextResponse.json(
15 { error: 'Authentication required' },
16 { status: 401 }
17 );
18 }
19
20 try {
21 // Fetch departments
22 let buckParams: Record<string, string> = {
23 "3": "retailmax.elink.departments",
24 "99": Math.random().toString()
25 };
26
27 // Use store-specific URL for API calls
28 const response = await fieldpineServerApi.buckApiCall(buckParams, authData.apiKey);
29
30 return NextResponse.json({
31 success: true,
32 data: response
33 });
34
35 } catch (error) {
36 console.error('Departments API error:', error);
37 return NextResponse.json(
38 { error: 'Failed to fetch departments' },
39 { status: 503 }
40 );
41 }
42
43 } catch (error) {
44 console.error('Departments API error:', error);
45 return NextResponse.json(
46 { error: 'Failed to fetch departments' },
47 { status: 500 }
48 );
49 }
50}