edgar.mendez 522235d441 Refactor supplier and unit of measure components and services
- Updated SupplierModal.vue to include new fields for supplier information and improved form validation.
- Enhanced Suppliers.vue to handle loading states and improved supplier data fetching logic.
- Removed old supplierServices and unitOfMeasureService files, replacing them with updated service files that align with new interfaces.
- Created new interfaces for suppliers and unit of measure to standardize data handling across the application.
- Adjusted the store files to reference the new service files and interfaces.
- Improved error handling and logging in service methods for better debugging.
2026-02-24 09:08:44 -06:00

41 lines
1.1 KiB
TypeScript

import { defineStore } from 'pinia';
import { ref } from 'vue';
import { supplierServices } from '../services/supplier.services';
import type { Supplier } from '../types/suppliers.interfaces';
export const useSupplierStore = defineStore('supplier', () => {
const suppliers = ref<Supplier[]>([]);
const loading = ref(false);
const error = ref<string | null>(null);
async function fetchAllSuppliers() {
loading.value = true;
error.value = null;
try {
const response = await supplierServices.getSuppliers(false);
// Si la respuesta es paginada, usar response.data; si es lista, usar response.suppliers o response directamente
if (Array.isArray(response)) {
suppliers.value = response as Supplier[];
} else if ('suppliers' in response) {
suppliers.value = (response as any).suppliers;
} else if ('data' in response) {
suppliers.value = (response as any).data;
} else {
suppliers.value = [];
}
} catch (e: any) {
error.value = e?.message || 'Error al cargar proveedores';
suppliers.value = [];
} finally {
loading.value = false;
}
}
return {
suppliers,
loading,
error,
fetchAllSuppliers,
};
});