feat: bootstrap auto virtual tryon admin frontend
This commit is contained in:
32
app/api/orders/route.ts
Normal file
32
app/api/orders/route.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import type { CreateOrderResponseDto } from "@/lib/types/backend";
|
||||
import { backendRequest } from "@/lib/http/backend-client";
|
||||
import {
|
||||
jsonSuccess,
|
||||
parseJsonBody,
|
||||
withErrorHandling,
|
||||
} from "@/lib/http/response";
|
||||
import { parseCreateOrderPayload } from "@/lib/validation/create-order";
|
||||
|
||||
function normalizeCreateOrderResponse(payload: CreateOrderResponseDto) {
|
||||
return {
|
||||
orderId: payload.order_id,
|
||||
workflowId: payload.workflow_id,
|
||||
status: payload.status,
|
||||
};
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
return withErrorHandling(async () => {
|
||||
const rawPayload = await parseJsonBody(request);
|
||||
const payload = parseCreateOrderPayload(rawPayload);
|
||||
const response = await backendRequest<CreateOrderResponseDto>("/orders", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
return jsonSuccess(normalizeCreateOrderResponse(response.data), {
|
||||
status: response.status,
|
||||
mode: "proxy",
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user