barsa 934a87330d Refactor Billing Controller to Improve Error Handling
- Replaced inline error throwing with NotFoundException in the BillingController to enhance error handling and provide clearer responses for missing WHMCS client mappings.
- Updated multiple methods to ensure consistent error management across the controller, improving maintainability and clarity in API responses.
2025-12-26 17:36:06 +09:00

35 lines
865 B
TypeScript

/**
* WHMCS Normalization Utilities (domain-internal)
*/
/**
* Normalize status using provided status map.
* Generic helper for consistent status mapping.
*/
export function normalizeStatus<T extends string>(
status: string | null | undefined,
statusMap: Record<string, T>,
defaultStatus: T
): T {
if (!status) return defaultStatus;
const mapped = statusMap[status.trim().toLowerCase()];
return mapped ?? defaultStatus;
}
/**
* Normalize billing cycle using provided cycle map.
* Generic helper for consistent cycle mapping.
*/
export function normalizeCycle<T extends string>(
cycle: string | null | undefined,
cycleMap: Record<string, T>,
defaultCycle: T
): T {
if (!cycle) return defaultCycle;
const normalized = cycle
.trim()
.toLowerCase()
.replace(/[_\s-]+/g, " ");
return cycleMap[normalized] ?? defaultCycle;
}