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 Suppliers by ID Endpoint
7 * GET /api/v1/openapi/suppliers/[id] - Get single supplier
8 */
9export async function GET(
10 request: NextRequest,
11 { params }: { params: Promise<{ id: string }> }
12) {
13 try {
14 const authData = await getStoredAuth();
15 if (!authData || !authData.authenticated) {
16 return NextResponse.json(
17 { error: 'Authentication required' },
18 { status: 401 }
19 );
20 }
21
22 const supplier = await fieldpineServerApi.apiCall(`/Suppliers/${await params.then(p => p.id)}`, {
23 cookie: authData.apiKey,
24 useOpenApi: true
25 });
26
27 return NextResponse.json({
28 success: true,
29 data: supplier,
30 source: 'openapi'
31 });
32
33 } catch (error) {
34 console.error('Supplier API error:', error);
35 return NextResponse.json(
36 { error: 'Failed to fetch supplier' },
37 { status: 500 }
38 );
39 }
40}