feat: bootstrap auto virtual tryon admin frontend
This commit is contained in:
36
app/api/orders/[orderId]/assets/route.ts
Normal file
36
app/api/orders/[orderId]/assets/route.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
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",
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user