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 StockTransfers Receive Endpoint
7 * POST /api/v1/openapi/stock-transfers/[id]/receive?location=5
8 * Acknowledge receipt of store-to-store stock transfer
9 */
10export async function POST(
11 request: NextRequest,
12 { params }: { params: Promise<{ id: string }> }
13) {
14 try {
15 const authData = await getStoredAuth();
16 if (!authData || !authData.authenticated) {
17 return NextResponse.json(
18 { error: 'Authentication required' },
19 { status: 401 }
20 );
21 }
22
23 const { searchParams } = new URL(request.url);
24 const queryParams: Record<string, string | number> = {};
25
26 const location = searchParams.get('location');
27 if (location) queryParams.location = parseInt(location);
28
29 const result = await fieldpineServerApi.apiCall(
30 `/StockTransfers/${await params.then(p => p.id)}/receive`,
31 {
32 method: 'POST',
33 params: queryParams,
34 cookie: authData.apiKey,
35 useOpenApi: true
36 }
37 );
38
39 return NextResponse.json({
40 success: true,
41 data: result,
42 source: 'openapi'
43 });
44
45 } catch (error) {
46 console.error('StockTransfers receive error:', error);
47 return NextResponse.json(
48 { error: 'Failed to receive stock transfer' },
49 { status: 500 }
50 );
51 }
52}