72 lines
2.7 KiB
TypeScript
72 lines
2.7 KiB
TypeScript
/**
|
|
* @ai-summary API calls for vehicles feature
|
|
*/
|
|
|
|
import { apiClient } from '../../../core/api/client';
|
|
import { Vehicle, CreateVehicleRequest, UpdateVehicleRequest, DropdownOption, VINDecodeResponse } from '../types/vehicles.types';
|
|
|
|
// All requests (including dropdowns) use authenticated apiClient
|
|
|
|
export const vehiclesApi = {
|
|
getAll: async (): Promise<Vehicle[]> => {
|
|
const response = await apiClient.get('/vehicles');
|
|
return response.data;
|
|
},
|
|
|
|
getById: async (id: string): Promise<Vehicle> => {
|
|
const response = await apiClient.get(`/vehicles/${id}`);
|
|
return response.data;
|
|
},
|
|
|
|
create: async (data: CreateVehicleRequest): Promise<Vehicle> => {
|
|
const response = await apiClient.post('/vehicles', data);
|
|
return response.data;
|
|
},
|
|
|
|
update: async (id: string, data: UpdateVehicleRequest): Promise<Vehicle> => {
|
|
const response = await apiClient.put(`/vehicles/${id}`, data);
|
|
return response.data;
|
|
},
|
|
|
|
delete: async (id: string): Promise<void> => {
|
|
await apiClient.delete(`/vehicles/${id}`);
|
|
},
|
|
|
|
// Dropdown API methods (authenticated) - proxied through vehicles capsule
|
|
getYears: async (): Promise<number[]> => {
|
|
const response = await apiClient.get('/vehicles/dropdown/years');
|
|
return response.data;
|
|
},
|
|
|
|
getMakes: async (year: number): Promise<DropdownOption[]> => {
|
|
const response = await apiClient.get(`/vehicles/dropdown/makes?year=${year}`);
|
|
return response.data;
|
|
},
|
|
|
|
getModels: async (year: number, makeId: number): Promise<DropdownOption[]> => {
|
|
const response = await apiClient.get(`/vehicles/dropdown/models?year=${year}&make_id=${makeId}`);
|
|
return response.data;
|
|
},
|
|
|
|
getTransmissions: async (year: number, makeId: number, modelId: number): Promise<DropdownOption[]> => {
|
|
const response = await apiClient.get(`/vehicles/dropdown/transmissions?year=${year}&make_id=${makeId}&model_id=${modelId}`);
|
|
return response.data;
|
|
},
|
|
|
|
getEngines: async (year: number, makeId: number, modelId: number, trimId: number): Promise<DropdownOption[]> => {
|
|
const response = await apiClient.get(`/vehicles/dropdown/engines?year=${year}&make_id=${makeId}&model_id=${modelId}&trim_id=${trimId}`);
|
|
return response.data;
|
|
},
|
|
|
|
getTrims: async (year: number, makeId: number, modelId: number): Promise<DropdownOption[]> => {
|
|
const response = await apiClient.get(`/vehicles/dropdown/trims?year=${year}&make_id=${makeId}&model_id=${modelId}`);
|
|
return response.data;
|
|
},
|
|
|
|
// VIN decode method - using unified platform endpoint
|
|
decodeVIN: async (vin: string): Promise<VINDecodeResponse> => {
|
|
const response = await apiClient.get(`/platform/vehicle?vin=${vin}`);
|
|
return response.data;
|
|
},
|
|
};
|