3.4 KiB
Codebase Audit - Redundancies and Inconsistencies
🔍 Findings
1. Duplicate Address Type Aliases ⚠️
Location: packages/domain/auth/contract.ts and packages/domain/customer/contract.ts
Both files export Address as an alias for CustomerAddress:
// customer/contract.ts
export type Address = CustomerAddress;
// auth/contract.ts
export type Address = CustomerAddress;
Issue: Redundant alias in auth domain Fix: Remove from auth/contract.ts, import from customer domain
2. Inconsistent Error Handling in UsersService ⚠️
Location: apps/bff/src/modules/users/users.service.ts
Issues:
- Some methods throw generic
Error()instead of NestJS exceptions - Inconsistent error messages
- Some errors expose technical details
Examples:
// ❌ Generic Error (lines 68, 84, 98, 119, 172, 194, 218, 469)
throw new Error("Failed to find user");
throw new Error("Failed to retrieve customer profile");
// ✅ Proper NestJS exception (lines 129, 133, 233, 248-256)
throw new NotFoundException("User not found");
throw new BadRequestException("Unable to update profile.");
Fix: Use NestJS exceptions consistently:
NotFoundExceptionfor not found errorsBadRequestExceptionfor validation/client errors- Never throw generic
Error()in services
3. Unused/Redundant Imports in UsersService ℹ️
Location: apps/bff/src/modules/users/users.service.ts
import { Activity } from "@customer-portal/domain/auth"; // Used
import type { CustomerAddress } from "@customer-portal/domain/customer"; // Not used (can use Address alias)
Fix: Use Address alias from domain for consistency
4. Hardcoded Currency in Dashboard ⚠️
Location: apps/bff/src/modules/users/users.service.ts:460
currency: "JPY", // Hardcoded
Issue: Should come from user's WHMCS profile or config Fix: Fetch from WHMCS client data
5. TODO Comment Not Implemented ℹ️
Location: apps/bff/src/modules/users/users.service.ts:459
openCases: 0, // TODO: Implement support cases when ready
Fix: Either implement or remove TODO if not planned
6. SalesforceService Unused Health Check ⚠️
Location: apps/bff/src/modules/users/users.service.ts:136-163
In the old getProfile() method:
// Check Salesforce health flag (do not override fields)
if (mapping?.sfAccountId) {
try {
await this.salesforceService.getAccount(mapping.sfAccountId);
} catch (error) {
// Just logs error, doesn't use the data
}
}
Issue: Fetches Salesforce account but doesn't use it Fix: Already fixed in new implementation - removed
✅ Previously Fixed Issues
- ✅ Removed Profile Fields from DB - firstName, lastName, company, phone
- ✅ Unified Update Endpoint - Single PATCH /me for profile + address
- ✅ Removed Deprecated Types - UpdateProfileRequest, UpdateAddressRequest, UserProfile, User
- ✅ Cleaned Mapper Utilities - Renamed to mapPrismaUserToAuthState
- ✅ Single Source of Truth - WHMCS for all profile data
📋 Recommended Fixes
Priority 1 (Critical)
- Fix inconsistent error handling in UsersService
- Remove duplicate Address alias from auth domain
Priority 2 (Important)
- Fix hardcoded currency
- Clean up redundant imports
Priority 3 (Nice to have)
- Remove or implement TODO comments