Files
auto-virtual-tryon-frontend/app/api/orders/[orderId]/assets/route.ts

37 lines
1.0 KiB
TypeScript

import { adaptAsset } from "@/lib/adapters/orders";
import { backendRequest } from "@/lib/http/backend-client";
import {
jsonSuccess,
parsePositiveIntegerParam,
withErrorHandling,
} from "@/lib/http/response";
import type { AssetDto } from "@/lib/types/backend";
import { businessEmptyState, READY_STATE } from "@/lib/types/view-models";
type RouteContext = {
params: Promise<{
orderId: string;
}>;
};
export async function GET(_request: Request, context: RouteContext) {
return withErrorHandling(async () => {
const { orderId: rawOrderId } = await context.params;
const orderId = parsePositiveIntegerParam(rawOrderId, "orderId");
const response = await backendRequest<AssetDto[]>(`/orders/${orderId}/assets`);
const items = response.data.map(adaptAsset);
return jsonSuccess(
{
items,
state: items.length
? READY_STATE
: businessEmptyState("暂无资产", "当前订单还没有生成可查看的资产列表。"),
},
{
mode: "proxy",
},
);
});
}