53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
// src/api/pedimentoDocuments.ts
|
|
import { fetchWithAuth } from '../fetchWithAuth';
|
|
|
|
export interface PedimentoDocument {
|
|
id: string;
|
|
organizacion: string;
|
|
pedimento: string;
|
|
pedimento_numero:string;
|
|
archivo: string;
|
|
document_type: number;
|
|
size: number;
|
|
extension: string;
|
|
created_at: string;
|
|
updated_at: string;
|
|
}
|
|
|
|
export interface PedimentoDocumentsResponse {
|
|
count: number;
|
|
next: string | null;
|
|
previous: string | null;
|
|
results: PedimentoDocument[];
|
|
}
|
|
|
|
const API_URL = import.meta.env.VITE_EFC_API_URL;
|
|
|
|
export async function fetchPedimentoDocuments(
|
|
page: number = 1,
|
|
pageSize: number = 10,
|
|
filters: {
|
|
pedimento_numero?: string;
|
|
extension?: string;
|
|
document_type?: string | number;
|
|
created_at?: string;
|
|
} = {},
|
|
pedimentoId: string = ''
|
|
): Promise<PedimentoDocumentsResponse> {
|
|
const params = new URLSearchParams();
|
|
params.append('page', String(page));
|
|
params.append('page_size', String(pageSize));
|
|
if (pedimentoId) params.append('pedimento', pedimentoId);
|
|
if (filters.pedimento_numero) params.append('pedimento_numero', filters.pedimento_numero);
|
|
if (filters.extension) params.append('extension', filters.extension);
|
|
if (filters.document_type) params.append('document_type', String(filters.document_type));
|
|
if (filters.created_at) params.append('created_at', filters.created_at);
|
|
|
|
const res = await fetchWithAuth(
|
|
`${API_URL}/record/documents/?${params.toString()}`
|
|
);
|
|
|
|
if (!res.ok) throw new Error('No autorizado o error en la petición');
|
|
return res.json();
|
|
}
|