78 lines
2.9 KiB
JavaScript
78 lines
2.9 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.paymentMethodValidationSchema = exports.userMappingValidationSchema = exports.skuValidationSchema = exports.orderBusinessValidationSchema = void 0;
|
|
const zod_1 = require("zod");
|
|
const requests_1 = require("../api/requests");
|
|
const identifiers_1 = require("../shared/identifiers");
|
|
exports.orderBusinessValidationSchema = requests_1.createOrderRequestSchema
|
|
.extend({
|
|
userId: identifiers_1.userIdSchema,
|
|
opportunityId: zod_1.z.string().optional(),
|
|
})
|
|
.refine(data => {
|
|
if (data.orderType === "Internet") {
|
|
const mainServiceSkus = data.skus.filter(sku => {
|
|
const upperSku = sku.toUpperCase();
|
|
return (!upperSku.includes("INSTALL") &&
|
|
!upperSku.includes("ADDON") &&
|
|
!upperSku.includes("ACTIVATION") &&
|
|
!upperSku.includes("FEE"));
|
|
});
|
|
return mainServiceSkus.length >= 1;
|
|
}
|
|
return true;
|
|
}, {
|
|
message: "Internet orders must have at least one main service SKU (non-installation, non-addon)",
|
|
path: ["skus"],
|
|
})
|
|
.refine(data => {
|
|
if (data.orderType === "SIM" && data.configurations) {
|
|
return data.configurations.simType !== undefined;
|
|
}
|
|
return true;
|
|
}, {
|
|
message: "SIM orders must specify SIM type",
|
|
path: ["configurations", "simType"],
|
|
})
|
|
.refine(data => {
|
|
if (data.configurations?.simType === "eSIM") {
|
|
return data.configurations.eid !== undefined && data.configurations.eid.length > 0;
|
|
}
|
|
return true;
|
|
}, {
|
|
message: "eSIM orders must provide EID",
|
|
path: ["configurations", "eid"],
|
|
})
|
|
.refine(data => {
|
|
if (data.configurations?.isMnp === "true") {
|
|
const required = ["mnpNumber", "portingLastName", "portingFirstName"];
|
|
return required.every(field => data.configurations?.[field] !== undefined);
|
|
}
|
|
return true;
|
|
}, {
|
|
message: "MNP orders must provide porting information",
|
|
path: ["configurations"],
|
|
});
|
|
exports.skuValidationSchema = zod_1.z.object({
|
|
sku: zod_1.z.string().min(1, "SKU is required"),
|
|
isActive: zod_1.z.boolean(),
|
|
productType: zod_1.z.enum(["Internet", "SIM", "VPN", "Addon", "Fee"]),
|
|
price: zod_1.z.number().nonnegative(),
|
|
currency: zod_1.z.string().length(3),
|
|
});
|
|
exports.userMappingValidationSchema = zod_1.z.object({
|
|
userId: identifiers_1.userIdSchema,
|
|
sfAccountId: zod_1.z.string().min(15, "Salesforce Account ID must be at least 15 characters"),
|
|
whmcsClientId: zod_1.z.number().int().positive("WHMCS Client ID must be positive"),
|
|
});
|
|
exports.paymentMethodValidationSchema = zod_1.z.object({
|
|
userId: identifiers_1.userIdSchema,
|
|
whmcsClientId: zod_1.z.number().int().positive(),
|
|
hasValidPaymentMethod: zod_1.z.boolean(),
|
|
paymentMethods: zod_1.z.array(zod_1.z.object({
|
|
id: zod_1.z.string(),
|
|
type: zod_1.z.string(),
|
|
isDefault: zod_1.z.boolean(),
|
|
})),
|
|
});
|
|
//# sourceMappingURL=orders.js.map
|