barsa d04b256885 Update documentation and remove unused files for codebase clarity
- Refreshed CODEBASE_ANALYSIS.md to reflect the new ownership model and improve onboarding documentation.
- Deleted obsolete VALIDATION_DUPLICATION_REPORT.md to streamline the codebase.
- Made minor adjustments to various components and services for better organization and clarity.
2025-10-27 15:47:50 +09:00

44 lines
1.4 KiB
TypeScript

import {
orderConfigurationsSchema,
orderSelectionsSchema,
type OrderConfigurations,
type CreateOrderRequest,
type OrderSelections,
} from "./schema";
import { ORDER_TYPE } from "./contract";
export function buildOrderConfigurations(selections: OrderSelections): OrderConfigurations {
const normalizedSelections = orderSelectionsSchema.parse(selections);
return orderConfigurationsSchema.parse({
...normalizedSelections,
address: normalizedSelections.address
? {
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,
}
: 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 } : {}),
};
}