64 lines
2.5 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkMappingCompleteness = checkMappingCompleteness;
exports.validateNoConflicts = validateNoConflicts;
exports.validateDeletion = validateDeletion;
exports.sanitizeCreateRequest = sanitizeCreateRequest;
exports.sanitizeUpdateRequest = sanitizeUpdateRequest;
function checkMappingCompleteness(request) {
const warnings = [];
if (!request.sfAccountId) {
warnings.push("Salesforce account ID not provided - mapping will be incomplete");
}
return warnings;
}
function validateNoConflicts(request, existingMappings) {
const errors = [];
const warnings = [];
const duplicateUser = existingMappings.find(m => m.userId === request.userId);
if (duplicateUser) {
errors.push(`User ${request.userId} already has a mapping`);
}
const duplicateWhmcs = existingMappings.find(m => m.whmcsClientId === request.whmcsClientId);
if (duplicateWhmcs) {
errors.push(`WHMCS client ${request.whmcsClientId} is already mapped to user ${duplicateWhmcs.userId}`);
}
if (request.sfAccountId) {
const duplicateSf = existingMappings.find(m => m.sfAccountId === request.sfAccountId);
if (duplicateSf) {
warnings.push(`Salesforce account ${request.sfAccountId} is already mapped to user ${duplicateSf.userId}`);
}
}
return { isValid: errors.length === 0, errors, warnings };
}
function validateDeletion(mapping) {
const errors = [];
const warnings = [];
if (!mapping) {
errors.push("Cannot delete non-existent mapping");
return { isValid: false, errors, warnings };
}
warnings.push("Deleting this mapping will prevent access to WHMCS/Salesforce data for this user");
if (mapping.sfAccountId) {
warnings.push("This mapping includes Salesforce integration - deletion will affect case management");
}
return { isValid: true, errors, warnings };
}
function sanitizeCreateRequest(request) {
return {
userId: request.userId?.trim(),
whmcsClientId: request.whmcsClientId,
sfAccountId: request.sfAccountId?.trim() || undefined,
};
}
function sanitizeUpdateRequest(request) {
const sanitized = {};
if (request.whmcsClientId !== undefined) {
sanitized.whmcsClientId = request.whmcsClientId;
}
if (request.sfAccountId !== undefined) {
sanitized.sfAccountId = request.sfAccountId?.trim() || undefined;
}
return sanitized;
}
//# sourceMappingURL=validation.js.map