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 * Recent Sales Endpoint
7 * Gets recent sales for accounts
8 */
9export async function GET(request: NextRequest) {
10 try {
11 // Verify authentication
12 const authData = await getStoredAuth();
13 if (!authData || !authData.authenticated) {
14 return NextResponse.json(
15 { success: false, error: 'Authentication required' },
16 { status: 401 }
17 );
18 }
19
20 try {
21 const buckParams = {
22 "3": "retailmax.elink.sale.list",
23 "9": "f108,ge,0&9=f101,gt,today-180&9=f505,0,1",
24 "8": "30",
25 "10": "903,904",
26 "13": "completeddt"
27 };
28
29 const response = await fieldpineServerApi.buckApiCall(buckParams, authData.apiKey);
30
31 if (response?.DATS && Array.isArray(response.DATS)) {
32 return NextResponse.json({
33 success: true,
34 data: response.DATS,
35 source: 'elink'
36 });
37 } else {
38 return NextResponse.json({
39 success: true,
40 data: [],
41 source: 'elink'
42 });
43 }
44
45 } catch (error) {
46 console.error('Recent sales error:', error);
47 return NextResponse.json(
48 { success: false, error: 'Failed to fetch recent sales', source: 'elink' },
49 { status: 503 }
50 );
51 }
52
53 } catch (error) {
54 console.error('Sales API error:', error);
55 return NextResponse.json(
56 { success: false, error: 'Failed to fetch sales' },
57 { status: 500 }
58 );
59 }
60}