refactor(frontend): migrate Customer domain to centralized API services

- Replaced all direct axios imports with service layer calls across 8 customer files
- Migrated core pages: home.vue, create.vue, edit.vue
- Migrated profile pages: profile.vue (1100+ lines), TankEstimation.vue
- Migrated supporting pages: ServicePlanEdit.vue, tank/edit.vue, list.vue

Services integrated:
- customerService: CRUD, descriptions, tank info, automatic status
- authService: authentication and Authorize.net account management
- paymentService: credit cards, transactions, payment authorization
- deliveryService: delivery records and automatic delivery data
- serviceService: service calls, parts, and service plans
- adminService: statistics, social comments, and reports
- queryService: dropdown data (customer types, states)

Type safety improvements:
- Updated paymentService.ts with accurate AxiosResponse types
- Fixed response unwrapping to match api.ts interceptor behavior
- Resolved all TypeScript errors in customer domain (0 errors)

Benefits:
- Consistent authentication via centralized interceptors
- Standardized error handling across all API calls
- Improved type safety with proper TypeScript interfaces
- Single source of truth for API endpoints
- Better testability through mockable services

Verified with vue-tsc --noEmit - all customer domain files pass type checking
This commit is contained in:
2026-02-01 13:00:21 -05:00
parent 5060ca8d9b
commit 72d8e35e06
59 changed files with 850 additions and 6220 deletions

View File

@@ -7,103 +7,105 @@ import {
CardListResponse,
CreateCardRequest,
PaymentRequest,
ApiResponse,
AxiosResponse,
TokenizeCardRequest,
UpdateTokenizedCardRequest,
ChargeSavedCardRequest,
ChargeDirectRequest,
CaptureRequest,
PreauthorizeSavedCardRequest,
AuthorizeNetTransactionResponse
AuthorizeNetTransactionResponse,
CardResponse,
CardsResponse
} from '../types/models';
export const paymentService = {
// Card management (Main API)
getCard: (id: number): Promise<ApiResponse<CreditCard>> =>
getCard: (id: number): Promise<AxiosResponse<CardResponse>> =>
api.get(`/payment/card/${id}`),
getCards: (customerId: number): Promise<ApiResponse<CreditCard[]>> =>
getCards: (customerId: number): Promise<AxiosResponse<CardsResponse>> =>
api.get(`/payment/cards/${customerId}`),
getCardsOnFile: (customerId: number): Promise<ApiResponse<CreditCard[]>> =>
getCardsOnFile: (customerId: number): Promise<AxiosResponse<CardsResponse>> =>
api.get(`/payment/cards/onfile/${customerId}`),
getAllCards: (page: number = 1): Promise<CardListResponse> =>
getAllCards: (page: number = 1): Promise<AxiosResponse<CardListResponse>> =>
api.get(`/payment/cards/all/${page}`),
createCard: (customerId: number, data: CreateCardRequest): Promise<ApiResponse<CreditCard>> =>
createCard: (customerId: number, data: CreateCardRequest): Promise<AxiosResponse<CardResponse>> =>
api.post(`/payment/card/create/${customerId}`, data),
updateCard: (id: number, data: Partial<CreditCard>): Promise<ApiResponse<CreditCard>> =>
updateCard: (id: number, data: Partial<CreditCard>): Promise<AxiosResponse<CardResponse>> =>
api.put(`/payment/card/edit/${id}`, data),
removeCard: (id: number): Promise<ApiResponse<void>> =>
removeCard: (id: number): Promise<AxiosResponse<{ ok: boolean }>> =>
api.delete(`/payment/card/remove/${id}`),
removeCardAlt: (id: number): Promise<ApiResponse<void>> =>
removeCardAlt: (id: number): Promise<AxiosResponse<{ ok: boolean }>> =>
api.delete(`/payment/cards/remove/${id}`),
updatePaymentProfile: (id: number, data: { auth_net_payment_profile_id: string }): Promise<ApiResponse<void>> =>
updatePaymentProfile: (id: number, data: { auth_net_payment_profile_id: string }): Promise<AxiosResponse<{ ok: boolean }>> =>
api.put(`/payment/card/update_payment_profile/${id}`, data),
// Authorization & capture (Main API)
authorizeDelivery: (id: number, data: PaymentRequest): Promise<ApiResponse<PaymentTransaction>> =>
authorizeDelivery: (id: number, data: PaymentRequest): Promise<AxiosResponse<PaymentTransaction & { ok: boolean }>> =>
api.put(`/payment/authorize/${id}`, data),
authorizeService: (id: number, data: PaymentRequest): Promise<ApiResponse<PaymentTransaction>> =>
authorizeService: (id: number, data: PaymentRequest): Promise<AxiosResponse<PaymentTransaction & { ok: boolean }>> =>
api.put(`/payment/authorize/service/${id}`, data),
cleanupAuthorization: (id: number): Promise<ApiResponse<void>> =>
cleanupAuthorization: (id: number): Promise<AxiosResponse<{ ok: boolean; message?: string; error?: string }>> =>
api.put(`/payment/authorize/cleanup/${id}`),
captureServicePayment: (id: number, data: { amount: number }): Promise<ApiResponse<PaymentTransaction>> =>
captureServicePayment: (id: number, data: { amount: number }): Promise<AxiosResponse<PaymentTransaction & { ok: boolean }>> =>
api.put(`/payment/capture/service/${id}`, data),
// Service payment
getServicePayment: (id: number, type: string): Promise<ApiResponse<{ amount: number }>> =>
getServicePayment: (id: number, type: string): Promise<AxiosResponse<{ amount: number; ok: boolean }>> =>
api.get(`/payment/service/payment/${id}/${type}`),
// Transactions
getDeliveryTransaction: (id: number): Promise<ApiResponse<PaymentTransaction>> =>
getDeliveryTransaction: (id: number): Promise<AxiosResponse<PaymentTransaction & { ok: boolean }>> =>
api.get(`/payment/transaction/delivery/${id}`),
getAuthorizeTransactions: (): Promise<ApiResponse<AuthorizeTransaction[]>> =>
getAuthorizeTransactions: (): Promise<AxiosResponse<AuthorizeTransaction[] & { ok: boolean }>> =>
api.get('/payment/transactions/authorize/1'),
getCustomerTransactions: (customerId: number, page: number = 1): Promise<TransactionListResponse> =>
getCustomerTransactions: (customerId: number, page: number = 1): Promise<AxiosResponse<TransactionListResponse>> =>
api.get(`/payment/transactions/customer/${customerId}/${page}`),
getServiceTransactions: (serviceId: number): Promise<ApiResponse<PaymentTransaction[]>> =>
getServiceTransactions: (serviceId: number): Promise<AxiosResponse<PaymentTransaction[] & { ok: boolean }>> =>
api.get(`/payment/transactions/service/${serviceId}`),
// Authorize.net endpoints
authorize: {
tokenizeCard: (customerId: number, data: TokenizeCardRequest): Promise<ApiResponse<CreditCard>> =>
tokenizeCard: (customerId: number, data: TokenizeCardRequest): Promise<AxiosResponse<CardResponse>> =>
authorizeApi.post(`/api/payments/customers/${customerId}/cards`, data),
updateTokenizedCard: (customerId: number, cardId: number, data: UpdateTokenizedCardRequest): Promise<ApiResponse<CreditCard>> =>
updateTokenizedCard: (customerId: number, cardId: number, data: UpdateTokenizedCardRequest): Promise<AxiosResponse<CardResponse>> =>
authorizeApi.put(`/api/payments/customers/${customerId}/cards/${cardId}`, data),
authorizeSavedCard: (customerId: number, data: PreauthorizeSavedCardRequest): Promise<ApiResponse<AuthorizeNetTransactionResponse>> =>
authorizeSavedCard: (customerId: number, data: PreauthorizeSavedCardRequest): Promise<AxiosResponse<AuthorizeNetTransactionResponse & { ok: boolean }>> =>
authorizeApi.post(`/api/payments/authorize/saved-card/${customerId}`, data),
chargeSavedCard: (customerId: number, data: ChargeSavedCardRequest): Promise<ApiResponse<AuthorizeNetTransactionResponse>> =>
chargeSavedCard: (customerId: number, data: ChargeSavedCardRequest): Promise<AxiosResponse<AuthorizeNetTransactionResponse & { ok: boolean }>> =>
authorizeApi.post(`/api/payments/charge/saved-card/${customerId}`, data),
charge: (customerId: number, data: ChargeDirectRequest): Promise<ApiResponse<AuthorizeNetTransactionResponse>> =>
charge: (customerId: number, data: ChargeDirectRequest): Promise<AxiosResponse<AuthorizeNetTransactionResponse & { ok: boolean }>> =>
authorizeApi.post(`/api/charge/${customerId}`, data),
capture: (data: CaptureRequest): Promise<ApiResponse<AuthorizeNetTransactionResponse>> =>
capture: (data: CaptureRequest): Promise<AxiosResponse<AuthorizeNetTransactionResponse & { ok: boolean }>> =>
authorizeApi.post('/api/payments/capture', data),
// Auto transaction endpoints
getAutoTransaction: (deliveryId: number): Promise<ApiResponse<AuthorizeNetTransactionResponse>> =>
getAutoTransaction: (deliveryId: number): Promise<AxiosResponse<AuthorizeNetTransactionResponse & { ok: boolean }>> =>
authorizeApi.get(`/api/auto/transaction/delivery/${deliveryId}`),
updateAutoTransactionId: (deliveryId: number, newId: number, data?: Record<string, unknown>): Promise<ApiResponse<void>> =>
updateAutoTransactionId: (deliveryId: number, newId: number, data?: Record<string, unknown>): Promise<AxiosResponse<{ ok: boolean }>> =>
authorizeApi.put(`/api/auto/transaction/delivery/${deliveryId}/update/${newId}`, data ?? {}),
linkTransactionToAuto: (transactionId: number, autoId: number, data?: Record<string, unknown>): Promise<ApiResponse<void>> =>
linkTransactionToAuto: (transactionId: number, autoId: number, data?: Record<string, unknown>): Promise<AxiosResponse<{ ok: boolean }>> =>
authorizeApi.put(`/api/transaction/${transactionId}/update_auto_id/${autoId}`, data ?? {}),
},
};