fix: se crea boton para ejecutar los procesos de consulta a ventanilla unica.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { fetchWithAuth } from '../fetchWithAuth';
|
||||
import { fetchWithAuth, postWithAuth } from '../fetchWithAuth';
|
||||
|
||||
// Tipos para la respuesta y registros
|
||||
export interface Task {
|
||||
@@ -51,3 +51,61 @@ export async function fetchTasks(
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// Interfaz para la respuesta del comando
|
||||
export interface ComandoResponse {
|
||||
message?: string;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
// Interfaz para los parámetros de ejecución
|
||||
export interface EjecutarComandoParams {
|
||||
procesamiento?: string;
|
||||
todos?: boolean;
|
||||
}
|
||||
|
||||
// API para ejecutar comando de procesamiento
|
||||
export async function ejecutarComando(
|
||||
params: EjecutarComandoParams
|
||||
): Promise<ComandoResponse> {
|
||||
try {
|
||||
const API_URL = (import.meta as any).env.VITE_EFC_API_URL;
|
||||
|
||||
console.log('API_URL:', API_URL);
|
||||
// Preparar los datos para la petición POST
|
||||
const requestData: any = {};
|
||||
|
||||
if (params.procesamiento !== undefined) {
|
||||
requestData.procesamiento = params.procesamiento;
|
||||
}
|
||||
|
||||
if (params.todos !== undefined) {
|
||||
requestData.todos = params.todos;
|
||||
}
|
||||
|
||||
// const res = await fetchWithAuth(`${API_URL}/customs/procesamientopedimentos-ejecutar-comando/`, {
|
||||
// method: 'POST',
|
||||
// headers: {
|
||||
// 'Content-Type': 'application/json',
|
||||
// },
|
||||
// body: JSON.stringify(requestData),
|
||||
// });
|
||||
|
||||
const res = await postWithAuth(`${API_URL}/customs/procesamientopedimentos-ejecutar-comando/`, requestData);
|
||||
|
||||
if (!res.ok) {
|
||||
// Intentar obtener el mensaje de error del servidor
|
||||
try {
|
||||
const errorData = await res.json();
|
||||
throw new Error(errorData.message || errorData.error || `Error ${res.status}: ${res.statusText}`);
|
||||
} catch {
|
||||
throw new Error(`Error ${res.status}: ${res.statusText}`);
|
||||
}
|
||||
}
|
||||
|
||||
return await res.json();
|
||||
} catch (error) {
|
||||
// console.error('Error in ejecutarComando:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user