Some checks failed
Build and Push Docker Images / docker (push) Failing after 2m11s
Next.js 16 breaking change: route params are now Promises
- Updated GET, PATCH, DELETE handlers to await params
- Changed signature from { params: { id: string } }
to { params: Promise<{ id: string }> }
- Extract id with: const { id } = await params;
89 lines
2.1 KiB
TypeScript
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 }
|
|
);
|
|
}
|
|
}
|