Se soluciono autenticacion
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { fetchWithAuth } from '../fetchWithAuth';
|
||||
|
||||
// Tipos para la respuesta y registros
|
||||
export interface ProcesamientoPedimento {
|
||||
id: number;
|
||||
@@ -20,14 +22,34 @@ export interface ProcesamientoPedimentosResponse {
|
||||
|
||||
// API para customs/procesamientopedimentos/
|
||||
export async function fetchProcesamientoPedimentos(
|
||||
token: string | null,
|
||||
page: number = 1,
|
||||
pageSize: number = 20
|
||||
pageSize: number = 20,
|
||||
filters: Record<string, any> = {}
|
||||
): Promise<ProcesamientoPedimentosResponse> {
|
||||
const API_URL = import.meta.env.VITE_EFC_API_URL;
|
||||
const headers: Record<string, string> = {};
|
||||
if (token) headers['Authorization'] = `Bearer ${token}`;
|
||||
const res = await fetch(`${API_URL}/customs/procesamientopedimentos/?page=${page}&page_size=${pageSize}`, { headers });
|
||||
if (!res.ok) throw new Error('Error al obtener procesamiento de pedimentos');
|
||||
return await res.json();
|
||||
try {
|
||||
const API_URL = (import.meta as any).env.VITE_EFC_API_URL;
|
||||
|
||||
// Construir query params
|
||||
const params = new URLSearchParams();
|
||||
params.append('page', String(page));
|
||||
params.append('page_size', String(pageSize));
|
||||
|
||||
// Agregar filtros
|
||||
Object.entries(filters).forEach(([key, value]) => {
|
||||
if (value !== undefined && value !== null && value !== '') {
|
||||
params.append(key, String(value));
|
||||
}
|
||||
});
|
||||
|
||||
const res = await fetchWithAuth(`${API_URL}/customs/procesamientopedimentos/?${params.toString()}`);
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error('Error al obtener procesamiento de pedimentos');
|
||||
}
|
||||
|
||||
return await res.json();
|
||||
} catch (error) {
|
||||
console.error('Error in fetchProcesamientoPedimentos:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user