Some checks failed
Build and Push Docker Images / docker (push) Failing after 1m57s
Phase 2 Backend Integration Complete: Backend Infrastructure: - Created NocoDB client abstraction layer (src/api/nocodbClient.ts) - Clean TypeScript API hiding NocoDB query syntax complexity - Helper methods for orders, stats, search, timeline, and filtering - Automatic date range handling and pagination support API Routes: - POST /api/admin/stats - Dashboard statistics with time range filtering - GET /api/admin/orders - List orders with search, filter, sort, pagination - GET /api/admin/orders/[id] - Single order details - PATCH /api/admin/orders/[id] - Update order fields - DELETE /api/admin/orders/[id] - Cancel order (soft delete) - GET /api/admin/orders/export - CSV/Excel export with filters Dashboard Updates: - Real-time data fetching from NocoDB - Time range selector (7d, 30d, 90d, all time) - Recharts line chart for orders timeline - Recharts pie chart for status distribution - Loading states and error handling - Dynamic stat cards with real numbers Dependencies Added: - papaparse - CSV export - xlsx - Excel export with styling - @types/papaparse - TypeScript support Data Types: - OrderRecord interface for NocoDB data structure - DashboardStats, TimelineData, OrderFilters interfaces - Full type safety across API and UI Environment Configuration: - NOCODB_BASE_URL, NOCODB_BASE_ID configured - NOCODB_API_KEY, NOCODB_ORDERS_TABLE_ID configured - All credentials stored securely in .env.local Ready for testing with sample data in NocoDB! 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
88 lines
2.8 KiB
TypeScript
88 lines
2.8 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { nocodbClient } from '@/api/nocodbClient';
|
|
import type { OrderFilters, PaginationParams } from '@/api/nocodbClient';
|
|
|
|
/**
|
|
* GET /api/admin/orders
|
|
* Get list of orders with filtering, sorting, and pagination
|
|
* Query params:
|
|
* - search: Text search across vessel name, IMO, order ID
|
|
* - status: Filter by order status
|
|
* - dateFrom, dateTo: Date range filter
|
|
* - limit: Page size (default: 50)
|
|
* - offset: Pagination offset
|
|
* - sortBy: Field to sort by
|
|
* - sortOrder: 'asc' | 'desc'
|
|
*/
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
const searchParams = request.nextUrl.searchParams;
|
|
const searchTerm = searchParams.get('search');
|
|
|
|
// Build filters
|
|
const filters: OrderFilters = {};
|
|
if (searchParams.get('status')) filters.status = searchParams.get('status')!;
|
|
if (searchParams.get('dateFrom')) filters.dateFrom = searchParams.get('dateFrom')!;
|
|
if (searchParams.get('dateTo')) filters.dateTo = searchParams.get('dateTo')!;
|
|
if (searchParams.get('vesselName')) filters.vesselName = searchParams.get('vesselName')!;
|
|
if (searchParams.get('imoNumber')) filters.imoNumber = searchParams.get('imoNumber')!;
|
|
|
|
// Build pagination
|
|
const pagination: PaginationParams = {
|
|
limit: parseInt(searchParams.get('limit') || '50'),
|
|
offset: parseInt(searchParams.get('offset') || '0'),
|
|
sortBy: searchParams.get('sortBy') || 'CreatedAt',
|
|
sortOrder: (searchParams.get('sortOrder') as 'asc' | 'desc') || 'desc',
|
|
};
|
|
|
|
// Use search if provided, otherwise use filters
|
|
const response = searchTerm
|
|
? await nocodbClient.searchOrders(searchTerm, pagination)
|
|
: await nocodbClient.getOrders(filters, pagination);
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
data: response.list,
|
|
pagination: response.pageInfo,
|
|
});
|
|
} catch (error) {
|
|
console.error('Error fetching orders:', error);
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
error: error instanceof Error ? error.message : 'Failed to fetch orders',
|
|
},
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* POST /api/admin/orders
|
|
* Create a new order (if needed for manual entry)
|
|
*/
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const body = await request.json();
|
|
|
|
// In a real implementation, you'd call nocodbClient to create the order
|
|
// For now, return a placeholder
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
error: 'Order creation not yet implemented',
|
|
},
|
|
{ status: 501 }
|
|
);
|
|
} catch (error) {
|
|
console.error('Error creating order:', error);
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
error: error instanceof Error ? error.message : 'Failed to create order',
|
|
},
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|