1import { NextRequest, NextResponse } from 'next/server';
2import { fieldpineServerApi } from '@/lib/server/fieldpineApi';
3import { getStoredAuth } from '@/lib/server/auth';
6 * Recent Sales Endpoint
7 * Gets recent sales for accounts
9export async function GET(request: NextRequest) {
11 // Verify authentication
12 const authData = await getStoredAuth();
13 if (!authData || !authData.authenticated) {
14 return NextResponse.json(
15 { success: false, error: 'Authentication required' },
22 "3": "retailmax.elink.sale.list",
23 "9": "f108,ge,0&9=f101,gt,today-180&9=f505,0,1",
29 const response = await fieldpineServerApi.buckApiCall(buckParams, authData.apiKey);
31 if (response?.DATS && Array.isArray(response.DATS)) {
32 return NextResponse.json({
38 return NextResponse.json({
46 console.error('Recent sales error:', error);
47 return NextResponse.json(
48 { success: false, error: 'Failed to fetch recent sales', source: 'elink' },
54 console.error('Sales API error:', error);
55 return NextResponse.json(
56 { success: false, error: 'Failed to fetch sales' },