- 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.
35 lines
865 B
TypeScript
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;
|
|
}
|