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 * OpenAPI Departments Endpoint
7 * GET /api/v1/openapi/departments - List all departments
8 */
9export async function GET(request: NextRequest) {
10 try {
11 const authData = await getStoredAuth();
12 if (!authData || !authData.authenticated) {
13 return NextResponse.json(
14 { error: 'Authentication required' },
15 { status: 401 }
16 );
17 }
18
19 const { searchParams } = new URL(request.url);
20 const params: Record<string, string | number> = {};
21
22 const limit = searchParams.get('limit');
23 if (limit) params.limit = parseInt(limit);
24
25 const departments = await fieldpineServerApi.apiCall("/Departments", {
26 params,
27 cookie: authData.apiKey,
28 useOpenApi: true
29 });
30
31 return NextResponse.json({
32 success: true,
33 data: departments,
34 source: 'openapi'
35 });
36
37 } catch (error) {
38 console.error('Departments API error:', error);
39 return NextResponse.json(
40 { error: 'Failed to fetch departments' },
41 { status: 500 }
42 );
43 }
44}