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

@@ -88,8 +88,8 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import axios from 'axios'
import authHeader from '../../../services/auth.header'
import { authService } from '../../../services/authService'
import { customerService } from '../../../services/customerService'
import Footer from '../../../layouts/footers/footer.vue'
// Interface for our flat form model
@@ -118,8 +118,7 @@ const TankForm = ref({
// Functions
const userStatus = () => {
const path = import.meta.env.VITE_BASE_URL + '/auth/whoami';
axios.get(path, { withCredentials: true, headers: authHeader() })
authService.whoami()
.then((response: any) => {
if (response.data.ok) {
user.value = response.data.user;
@@ -128,31 +127,27 @@ const userStatus = () => {
.catch(() => { user.value = null; });
}
const getCustomer = (userid: any) => {
const path = `${import.meta.env.VITE_BASE_URL}/customer/${userid}`;
axios.get(path, { headers: authHeader() })
const getCustomer = (userid: number) => {
customerService.getById(userid)
.then((response: any) => {
customer.value = response.data;
customer.value = response.data?.customer || response.data;
});
}
const getCustomerDescription = (userid: any) => {
const path = `${import.meta.env.VITE_BASE_URL}/customer/description/${userid}`;
axios.get(path, { headers: authHeader() })
const getCustomerDescription = (userid: number) => {
customerService.getDescription(userid)
.then((response: any) => {
// Only update fill_location if the response has it
if (response.data && response.data.fill_location) {
TankForm.value.fill_location = response.data.fill_location;
const description = response.data?.description || response.data;
if (description && description.fill_location) {
TankForm.value.fill_location = description.fill_location;
}
});
}
const getTank = (customer_id: any) => {
const path = `${import.meta.env.VITE_BASE_URL}/customer/tank/${customer_id}`;
axios.get(path, { withCredentials: true, headers: authHeader() })
const getTank = (customer_id: number) => {
customerService.getTank(customer_id)
.then((response: any) => {
if (response.data) {
// Update the form model with data from the tank endpoint
TankForm.value.last_tank_inspection = response.data.last_tank_inspection;
TankForm.value.tank_status = response.data.tank_status;
TankForm.value.outside_or_inside = response.data.outside_or_inside;
@@ -162,8 +157,7 @@ const getTank = (customer_id: any) => {
}
const editTank = (payload: TankFormData) => {
const path = `${import.meta.env.VITE_BASE_URL}/customer/edit/tank/${route.params.id}`;
axios.put(path, payload, { withCredentials: true, headers: authHeader() })
customerService.updateTank(parseInt(route.params.id as string), payload)
.then((response: any) => {
if (response.data.ok) {
router.push({ name: "customerProfile", params: { id: customer.value.id } });
@@ -181,7 +175,7 @@ const onSubmit = () => {
// Lifecycle
onMounted(() => {
userStatus();
const customerId = route.params.id;
const customerId = parseInt(route.params.id as string);
getCustomer(customerId);
getCustomerDescription(customerId);
getTank(customerId);