33 lines
964 B
TypeScript
33 lines
964 B
TypeScript
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",
|
|
});
|
|
});
|
|
}
|