Matt 7751976fc9
All checks were successful
Build and Push Docker Images / docker (push) Successful in 2m28s
Fix all remaining TypeScript build errors
- Import and use OffsetOrderSource type in wrenClient.ts
- Fix Recharts PieChart label rendering with proper props
- Remove unused POST body parameter in orders route

All TypeScript errors now resolved, build succeeds.
2025-11-03 12:02:05 +01:00

89 lines
2.1 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server';
import { nocodbClient } from '@/api/nocodbClient';
/**
* GET /api/admin/orders/[id]
* Get single order by record ID
*/
export async function GET(
_request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const { id } = await params;
const order = await nocodbClient.getOrderById(id);
return NextResponse.json({
success: true,
data: order,
});
} catch (error) {
console.error('Error fetching order:', error);
return NextResponse.json(
{
success: false,
error: error instanceof Error ? error.message : 'Failed to fetch order',
},
{ status: 500 }
);
}
}
/**
* PATCH /api/admin/orders/[id]
* Update order fields (commonly used for status updates)
*/
export async function PATCH(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const { id } = await params;
const body = await request.json();
const updatedOrder = await nocodbClient.updateOrder(id, body);
return NextResponse.json({
success: true,
data: updatedOrder,
});
} catch (error) {
console.error('Error updating order:', error);
return NextResponse.json(
{
success: false,
error: error instanceof Error ? error.message : 'Failed to update order',
},
{ status: 500 }
);
}
}
/**
* DELETE /api/admin/orders/[id]
* Delete/archive an order
*/
export async function DELETE(
_request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const { id } = await params;
// Instead of actually deleting, update status to "cancelled"
await nocodbClient.updateOrderStatus(id, 'cancelled');
return NextResponse.json({
success: true,
message: 'Order cancelled successfully',
});
} catch (error) {
console.error('Error cancelling order:', error);
return NextResponse.json(
{
success: false,
error: error instanceof Error ? error.message : 'Failed to cancel order',
},
{ status: 500 }
);
}
}