74 lines
2.3 KiB
TypeScript
74 lines
2.3 KiB
TypeScript
|
|
import { z } from "zod";
|
||
|
|
|
||
|
|
import {
|
||
|
|
orderConfigurationsSchema,
|
||
|
|
type OrderConfigurations,
|
||
|
|
type CreateOrderRequest,
|
||
|
|
} from "./schema";
|
||
|
|
import { ORDER_TYPE } from "./contract";
|
||
|
|
|
||
|
|
const orderSelectionsSchema = z.object({
|
||
|
|
accessMode: z.enum(["IPoE-BYOR", "IPoE-HGW", "PPPoE"]).optional(),
|
||
|
|
activationType: z.enum(["Immediate", "Scheduled"]).optional(),
|
||
|
|
scheduledAt: z.string().optional(),
|
||
|
|
simType: z.enum(["eSIM", "Physical SIM"]).optional(),
|
||
|
|
eid: z.string().optional(),
|
||
|
|
isMnp: z.string().optional(),
|
||
|
|
mnpNumber: z.string().optional(),
|
||
|
|
mnpExpiry: z.string().optional(),
|
||
|
|
mnpPhone: z.string().optional(),
|
||
|
|
mvnoAccountNumber: z.string().optional(),
|
||
|
|
portingLastName: z.string().optional(),
|
||
|
|
portingFirstName: z.string().optional(),
|
||
|
|
portingLastNameKatakana: z.string().optional(),
|
||
|
|
portingFirstNameKatakana: z.string().optional(),
|
||
|
|
portingGender: z.enum(["Male", "Female", "Corporate/Other"]).optional(),
|
||
|
|
portingDateOfBirth: z.string().optional(),
|
||
|
|
address: z
|
||
|
|
.object({
|
||
|
|
street: z.string().optional(),
|
||
|
|
streetLine2: z.string().optional(),
|
||
|
|
city: z.string().optional(),
|
||
|
|
state: z.string().optional(),
|
||
|
|
postalCode: z.string().optional(),
|
||
|
|
country: z.string().optional(),
|
||
|
|
})
|
||
|
|
.optional(),
|
||
|
|
});
|
||
|
|
|
||
|
|
export type OrderSelections = z.infer<typeof orderSelectionsSchema>;
|
||
|
|
|
||
|
|
export function buildOrderConfigurations(selections: OrderSelections): OrderConfigurations {
|
||
|
|
return orderConfigurationsSchema.parse({
|
||
|
|
...selections,
|
||
|
|
address: selections.address
|
||
|
|
? {
|
||
|
|
street: selections.address.street ?? null,
|
||
|
|
streetLine2: selections.address.streetLine2 ?? null,
|
||
|
|
city: selections.address.city ?? null,
|
||
|
|
state: selections.address.state ?? null,
|
||
|
|
postalCode: selections.address.postalCode ?? null,
|
||
|
|
country: selections.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 } : {}),
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
|