2 * FD1 Sale Detail API Route
4 * GET /api/v1/fd1/sales/[id] - Get single sale by ID with line items
7import { NextRequest, NextResponse } from 'next/server';
8import { getRequestContext } from '@/lib/server/sessionUtils';
9import { createFD1Client } from '@/lib/client/fd1Client';
11export async function GET(
13 { params }: { params: Promise<{ id: string }> }
16 const context = await getRequestContext(request);
18 if (!context?.session?.storeUrl) {
19 return NextResponse.json(
20 { success: false, error: 'Not authenticated' },
25 const { id } = await params;
26 const saleId = parseInt(id, 10);
29 return NextResponse.json(
30 { success: false, error: 'Invalid sale ID' },
36 const fd1Client = createFD1Client({
37 baseUrl: context.session.storeUrl!,
38 apiKey: context.session.apiKey,
43 const sale = await fd1Client.getSale(saleId);
46 return NextResponse.json(
47 { success: false, error: 'Sale not found' },
52 return NextResponse.json({
58 console.error('FD1 sale detail API error:', error);
59 return NextResponse.json(
62 error: error instanceof Error ? error.message : 'Failed to fetch sale',