2025-10-20 13:53:35 +09:00
|
|
|
import {
|
|
|
|
|
orderConfigurationsSchema,
|
2025-10-27 15:47:50 +09:00
|
|
|
orderSelectionsSchema,
|
2025-10-20 13:53:35 +09:00
|
|
|
type OrderConfigurations,
|
|
|
|
|
type CreateOrderRequest,
|
2025-10-27 15:47:50 +09:00
|
|
|
type OrderSelections,
|
2025-10-20 13:53:35 +09:00
|
|
|
} from "./schema";
|
|
|
|
|
import { ORDER_TYPE } from "./contract";
|
|
|
|
|
|
|
|
|
|
export function buildOrderConfigurations(selections: OrderSelections): OrderConfigurations {
|
2025-10-27 15:47:50 +09:00
|
|
|
const normalizedSelections = orderSelectionsSchema.parse(selections);
|
|
|
|
|
|
2025-10-20 13:53:35 +09:00
|
|
|
return orderConfigurationsSchema.parse({
|
2025-10-27 15:47:50 +09:00
|
|
|
...normalizedSelections,
|
|
|
|
|
address: normalizedSelections.address
|
2025-10-20 13:53:35 +09:00
|
|
|
? {
|
2025-10-27 15:47:50 +09:00
|
|
|
street: normalizedSelections.address.street ?? null,
|
|
|
|
|
streetLine2: normalizedSelections.address.streetLine2 ?? null,
|
|
|
|
|
city: normalizedSelections.address.city ?? null,
|
|
|
|
|
state: normalizedSelections.address.state ?? null,
|
|
|
|
|
postalCode: normalizedSelections.address.postalCode ?? null,
|
|
|
|
|
country: normalizedSelections.address.country ?? null,
|
2025-10-20 13:53:35 +09:00
|
|
|
}
|
|
|
|
|
: undefined,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function createOrderRequest(payload: {
|
|
|
|
|
orderType?: string;
|
|
|
|
|
skus: string[];
|
|
|
|
|
configurations?: OrderSelections | null;
|
|
|
|
|
}): CreateOrderRequest {
|
|
|
|
|
const orderType = (payload.orderType ?? ORDER_TYPE.OTHER) as CreateOrderRequest["orderType"];
|
|
|
|
|
const configurations = payload.configurations
|
|
|
|
|
? buildOrderConfigurations(payload.configurations)
|
|
|
|
|
: undefined;
|
|
|
|
|
return {
|
|
|
|
|
orderType,
|
|
|
|
|
skus: payload.skus,
|
|
|
|
|
...(configurations ? { configurations } : {}),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|