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 const want = searchParams.get("want") || "";
14
15 let endpoint = "/OpenApi/staff";
16 if (want) {
17 endpoint += `?want=${want}`;
18 }
19
20 const result = await fieldpineServerApi.apiCall(endpoint, {
21 method: "GET",
22 cookie: authData.apiKey!,
23 });
24
25 return NextResponse.json({
26 success: true,
27 data: result,
28 source: "openapi",
29 });
30 } catch (error: any) {
31 console.error("Error fetching staff:", error);
32 return NextResponse.json(
33 { success: false, error: error.message || "Failed to fetch staff" },
34 { status: error.status || 500 }
35 );
36 }
37}