From 67691a50b5091593c5b88d772128dd1dc9e9564b Mon Sep 17 00:00:00 2001 From: barsa Date: Tue, 4 Nov 2025 11:14:26 +0900 Subject: [PATCH] Refactor WHMCS service and improve address handling - Updated WHMCS service to utilize addressSchema for client address retrieval, enhancing data validation. - Cleaned up imports in WHMCS client service for better organization. - Improved logging format in WHMCS subscription service for clearer output. - Streamlined address handling in order builder service for consistency. - Enhanced code readability by formatting JSX elements in ProfileContainer and other components. - Removed deprecated billing cycle normalization logic and centralized it in the domain helpers for better maintainability. --- .../whmcs/services/whmcs-client.service.ts | 5 +- .../services/whmcs-subscription.service.ts | 4 +- .../src/integrations/whmcs/whmcs.service.ts | 9 +- .../orders/services/order-builder.service.ts | 4 +- .../account/views/ProfileContainer.tsx | 18 +-- .../auth/components/SignupForm/SignupForm.tsx | 17 +-- .../src/features/auth/hooks/use-auth.ts | 9 +- .../src/features/auth/views/LoginView.tsx | 5 +- .../features/orders/components/OrderCard.tsx | 8 +- .../features/orders/utils/order-presenters.ts | 28 ++-- .../src/features/orders/views/OrderDetail.tsx | 13 +- .../src/features/orders/views/OrdersList.tsx | 11 +- .../SubscriptionTable/SubscriptionTable.tsx | 6 +- .../components/SubscriptionTable/index.ts | 5 +- .../views/SubscriptionDetail.tsx | 4 +- .../subscriptions/views/SubscriptionsList.tsx | 6 +- packages/domain/auth/helpers.ts | 14 ++ packages/domain/auth/index.ts | 2 + packages/domain/customer/schema.ts | 125 +++++++++--------- packages/domain/orders/helpers.ts | 60 +++++++++ packages/domain/orders/index.ts | 1 + .../orders/providers/salesforce/mapper.ts | 6 +- .../domain/orders/providers/whmcs/mapper.ts | 13 +- 23 files changed, 218 insertions(+), 155 deletions(-) create mode 100644 packages/domain/auth/helpers.ts diff --git a/apps/bff/src/integrations/whmcs/services/whmcs-client.service.ts b/apps/bff/src/integrations/whmcs/services/whmcs-client.service.ts index 74b5fe80..072f5182 100644 --- a/apps/bff/src/integrations/whmcs/services/whmcs-client.service.ts +++ b/apps/bff/src/integrations/whmcs/services/whmcs-client.service.ts @@ -10,10 +10,7 @@ import type { WhmcsAddClientResponse, WhmcsValidateLoginResponse, } from "@customer-portal/domain/customer"; -import { - Providers as CustomerProviders, - type WhmcsClient, -} from "@customer-portal/domain/customer"; +import { Providers as CustomerProviders, type WhmcsClient } from "@customer-portal/domain/customer"; @Injectable() export class WhmcsClientService { diff --git a/apps/bff/src/integrations/whmcs/services/whmcs-subscription.service.ts b/apps/bff/src/integrations/whmcs/services/whmcs-subscription.service.ts index 06d660b0..4f69e441 100644 --- a/apps/bff/src/integrations/whmcs/services/whmcs-subscription.service.ts +++ b/apps/bff/src/integrations/whmcs/services/whmcs-subscription.service.ts @@ -85,7 +85,9 @@ export class WhmcsSubscriptionService { // Cache the result await this.cacheService.setSubscriptionsList(userId, result); - this.logger.log(`Fetched ${result.subscriptions.length} subscriptions for client ${clientId}`); + this.logger.log( + `Fetched ${result.subscriptions.length} subscriptions for client ${clientId}` + ); // Apply status filter if needed if (filters.status) { diff --git a/apps/bff/src/integrations/whmcs/whmcs.service.ts b/apps/bff/src/integrations/whmcs/whmcs.service.ts index c7126b01..30cb89b6 100644 --- a/apps/bff/src/integrations/whmcs/whmcs.service.ts +++ b/apps/bff/src/integrations/whmcs/whmcs.service.ts @@ -2,7 +2,12 @@ import { Injectable, Inject } from "@nestjs/common"; import type { Invoice, InvoiceList } from "@customer-portal/domain/billing"; import type { Subscription, SubscriptionList } from "@customer-portal/domain/subscriptions"; import type { PaymentMethodList, PaymentGatewayList } from "@customer-portal/domain/payments"; -import { Providers as CustomerProviders, type Address, type WhmcsClient } from "@customer-portal/domain/customer"; +import { + Providers as CustomerProviders, + addressSchema, + type Address, + type WhmcsClient, +} from "@customer-portal/domain/customer"; import { WhmcsConnectionOrchestratorService } from "./connection/services/whmcs-connection-orchestrator.service"; import { WhmcsInvoiceService, InvoiceFilters } from "./services/whmcs-invoice.service"; import { @@ -150,7 +155,7 @@ export class WhmcsService { */ async getClientAddress(clientId: number): Promise
{ const customer = await this.clientService.getClientDetails(clientId); - return (customer.address ?? {}) as Address; + return addressSchema.parse(customer.address ?? {}); } async updateClientAddress(clientId: number, address: Partial
): Promise { diff --git a/apps/bff/src/modules/orders/services/order-builder.service.ts b/apps/bff/src/modules/orders/services/order-builder.service.ts index 04c7e60c..c7a5c8e4 100644 --- a/apps/bff/src/modules/orders/services/order-builder.service.ts +++ b/apps/bff/src/modules/orders/services/order-builder.service.ts @@ -118,15 +118,13 @@ export class OrderBuilder { | undefined; const addressChanged = !!orderAddress; const addressToUse = orderAddress || address; - const address1 = typeof addressToUse?.address1 === "string" ? addressToUse.address1 : ""; const address2 = typeof addressToUse?.address2 === "string" ? addressToUse.address2 : ""; const fullStreet = [address1, address2].filter(Boolean).join(", "); orderFields.BillingStreet = fullStreet; orderFields.BillingCity = typeof addressToUse?.city === "string" ? addressToUse.city : ""; - orderFields.BillingState = - typeof addressToUse?.state === "string" ? addressToUse.state : ""; + orderFields.BillingState = typeof addressToUse?.state === "string" ? addressToUse.state : ""; orderFields.BillingPostalCode = typeof addressToUse?.postcode === "string" ? addressToUse.postcode : ""; orderFields.BillingCountry = diff --git a/apps/portal/src/features/account/views/ProfileContainer.tsx b/apps/portal/src/features/account/views/ProfileContainer.tsx index f2f893cb..389a87ae 100644 --- a/apps/portal/src/features/account/views/ProfileContainer.tsx +++ b/apps/portal/src/features/account/views/ProfileContainer.tsx @@ -178,9 +178,9 @@ export default function ProfileContainer() {

Personal Information

{!editingProfile && ( -