- 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.
30 lines
769 B
TypeScript
30 lines
769 B
TypeScript
/**
|
|
* WHMCS Parsing Utilities (domain-internal)
|
|
*/
|
|
|
|
/**
|
|
* Parse amount from WHMCS API response.
|
|
* WHMCS returns amounts as strings or numbers.
|
|
*/
|
|
export function parseAmount(amount: string | number | undefined): number {
|
|
if (typeof amount === "number") return amount;
|
|
if (!amount) return 0;
|
|
|
|
const cleaned = String(amount).replace(/[^\d.-]/g, "");
|
|
const parsed = Number.parseFloat(cleaned);
|
|
return Number.isNaN(parsed) ? 0 : parsed;
|
|
}
|
|
|
|
/**
|
|
* Format date from WHMCS API to ISO string.
|
|
* Returns undefined if input is invalid.
|
|
*/
|
|
export function formatDate(input?: string | null): string | undefined {
|
|
if (!input) return undefined;
|
|
|
|
const date = new Date(input);
|
|
if (Number.isNaN(date.getTime())) return undefined;
|
|
|
|
return date.toISOString();
|
|
}
|