78 lines
2.9 KiB
JavaScript
78 lines
2.9 KiB
JavaScript
|
|
"use strict";
|
||
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
|
exports.orderWithSkuValidationSchema = void 0;
|
||
|
|
exports.hasSimServicePlan = hasSimServicePlan;
|
||
|
|
exports.hasSimActivationFee = hasSimActivationFee;
|
||
|
|
exports.hasVpnActivationFee = hasVpnActivationFee;
|
||
|
|
exports.hasInternetServicePlan = hasInternetServicePlan;
|
||
|
|
exports.getMainServiceSkus = getMainServiceSkus;
|
||
|
|
exports.getOrderTypeValidationError = getOrderTypeValidationError;
|
||
|
|
const schema_1 = require("./schema");
|
||
|
|
function hasSimServicePlan(skus) {
|
||
|
|
return skus.some((sku) => sku.toUpperCase().includes("SIM") &&
|
||
|
|
!sku.toUpperCase().includes("ACTIVATION") &&
|
||
|
|
!sku.toUpperCase().includes("ADDON"));
|
||
|
|
}
|
||
|
|
function hasSimActivationFee(skus) {
|
||
|
|
return skus.some((sku) => sku.toUpperCase().includes("ACTIVATION") ||
|
||
|
|
sku.toUpperCase().includes("SIM-ACTIVATION"));
|
||
|
|
}
|
||
|
|
function hasVpnActivationFee(skus) {
|
||
|
|
return skus.some((sku) => sku.toUpperCase().includes("VPN") &&
|
||
|
|
sku.toUpperCase().includes("ACTIVATION"));
|
||
|
|
}
|
||
|
|
function hasInternetServicePlan(skus) {
|
||
|
|
return skus.some((sku) => sku.toUpperCase().includes("INTERNET") &&
|
||
|
|
!sku.toUpperCase().includes("INSTALL") &&
|
||
|
|
!sku.toUpperCase().includes("ADDON"));
|
||
|
|
}
|
||
|
|
function getMainServiceSkus(skus) {
|
||
|
|
return skus.filter((sku) => {
|
||
|
|
const upperSku = sku.toUpperCase();
|
||
|
|
return (!upperSku.includes("INSTALL") &&
|
||
|
|
!upperSku.includes("ADDON") &&
|
||
|
|
!upperSku.includes("ACTIVATION") &&
|
||
|
|
!upperSku.includes("FEE"));
|
||
|
|
});
|
||
|
|
}
|
||
|
|
exports.orderWithSkuValidationSchema = schema_1.orderBusinessValidationSchema
|
||
|
|
.refine((data) => data.orderType !== "SIM" || hasSimServicePlan(data.skus), {
|
||
|
|
message: "SIM orders must include a SIM service plan",
|
||
|
|
path: ["skus"],
|
||
|
|
})
|
||
|
|
.refine((data) => data.orderType !== "SIM" || hasSimActivationFee(data.skus), {
|
||
|
|
message: "SIM orders require an activation fee",
|
||
|
|
path: ["skus"],
|
||
|
|
})
|
||
|
|
.refine((data) => data.orderType !== "VPN" || hasVpnActivationFee(data.skus), {
|
||
|
|
message: "VPN orders require an activation fee",
|
||
|
|
path: ["skus"],
|
||
|
|
})
|
||
|
|
.refine((data) => data.orderType !== "Internet" || hasInternetServicePlan(data.skus), {
|
||
|
|
message: "Internet orders require a service plan",
|
||
|
|
path: ["skus"],
|
||
|
|
});
|
||
|
|
function getOrderTypeValidationError(orderType, skus) {
|
||
|
|
switch (orderType) {
|
||
|
|
case "SIM":
|
||
|
|
if (!hasSimServicePlan(skus)) {
|
||
|
|
return "A SIM plan must be selected";
|
||
|
|
}
|
||
|
|
if (!hasSimActivationFee(skus)) {
|
||
|
|
return "SIM orders require an activation fee";
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
case "VPN":
|
||
|
|
if (!hasVpnActivationFee(skus)) {
|
||
|
|
return "VPN orders require an activation fee";
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
case "Internet":
|
||
|
|
if (!hasInternetServicePlan(skus)) {
|
||
|
|
return "Internet orders require a service plan";
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
//# sourceMappingURL=validation.js.map
|