feature/digitalizacion-api
This commit is contained in:
@@ -15,6 +15,10 @@ export interface ExpedienteArchivo {
|
||||
task_id?: string | null;
|
||||
external_task_id?: string | null;
|
||||
acuse_pdf_path?: string | null;
|
||||
envio_xml_path?: string | null;
|
||||
respuesta_xml_path?: string | null;
|
||||
consulta_envio_xml_path?: string | null;
|
||||
consulta_respuesta_xml_path?: string | null;
|
||||
company_id: number;
|
||||
tenant_id: number;
|
||||
}
|
||||
@@ -39,10 +43,10 @@ export interface ExpedienteArchivoCreateDTO {
|
||||
}
|
||||
|
||||
export interface DigitalizarRequest {
|
||||
rfc_consulta: string;
|
||||
clave_documento: string;
|
||||
nombre_archivo: string;
|
||||
archivo_base64: string;
|
||||
rfc_consulta?: string | null;
|
||||
clave_documento?: string | null;
|
||||
nombre_archivo?: string | null;
|
||||
archivo_base64?: string | null;
|
||||
}
|
||||
|
||||
export interface DigitalizarResponse {
|
||||
@@ -51,6 +55,13 @@ export interface DigitalizarResponse {
|
||||
status: string;
|
||||
}
|
||||
|
||||
export interface ExpedienteArchivoUploadResponse {
|
||||
message: string;
|
||||
record_id: number;
|
||||
path: string;
|
||||
nombre_archivo?: string | null;
|
||||
}
|
||||
|
||||
export interface DigitalizacionResult {
|
||||
status?: string | null;
|
||||
message?: string | null;
|
||||
@@ -76,6 +87,7 @@ export interface DigitalizacionErrorDetail {
|
||||
|
||||
export interface DigitalizacionTaskDetailResponse {
|
||||
task_id: string;
|
||||
external_task_id?: string | null;
|
||||
state: string;
|
||||
status?: string | null;
|
||||
current_step?: string | null;
|
||||
@@ -132,6 +144,20 @@ class ExpedienteArchivosApi {
|
||||
return api.delete<void>(`${this.baseUrl}/${id}?${q}`);
|
||||
}
|
||||
|
||||
async uploadFile(
|
||||
id: number,
|
||||
file: File,
|
||||
companyId: string | number
|
||||
): Promise<ApiResponse<ExpedienteArchivoUploadResponse>> {
|
||||
const q = new URLSearchParams({ company_id: companyId.toString() });
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
return api.request<ExpedienteArchivoUploadResponse>(`${this.baseUrl}/${id}/upload?${q}`, {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
}
|
||||
|
||||
async digitalizar(
|
||||
id: number,
|
||||
body: DigitalizarRequest,
|
||||
@@ -146,6 +172,41 @@ class ExpedienteArchivosApi {
|
||||
`${this.baseUrl}/status-digitalizacion-task/${taskId}`
|
||||
);
|
||||
}
|
||||
|
||||
async downloadArtifact(
|
||||
id: number,
|
||||
artifactType: 'acuse' | 'envio-xml' | 'respuesta-xml' | 'consulta-envio-xml' | 'consulta-respuesta-xml',
|
||||
companyId: string | number,
|
||||
filename?: string
|
||||
): Promise<void> {
|
||||
const q = new URLSearchParams({ company_id: companyId.toString() });
|
||||
const endpoint = `${this.baseUrl}/${id}/artifacts/${artifactType}?${q}`;
|
||||
const blob = await api.getBlob(endpoint);
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = filename || `artifact_${id}`;
|
||||
a.style.display = 'none';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
async downloadAllArtifactsZip(id: number, companyId: string | number, baseName?: string): Promise<void> {
|
||||
const q = new URLSearchParams({ company_id: companyId.toString() });
|
||||
const endpoint = `${this.baseUrl}/${id}/artifacts-zip?${q}`;
|
||||
const blob = await api.getBlob(endpoint);
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `expediente_${baseName || id}.zip`;
|
||||
a.style.display = 'none';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
}
|
||||
|
||||
export const expedienteArchivosApi = new ExpedienteArchivosApi();
|
||||
|
||||
@@ -7,70 +7,52 @@ export interface DocumentTypeDigitization {
|
||||
active: boolean;
|
||||
}
|
||||
|
||||
export interface DocumentTypeDigitizationCreate {
|
||||
code: string;
|
||||
description: string;
|
||||
active?: boolean;
|
||||
}
|
||||
|
||||
export interface DocumentTypeDigitizationUpdate {
|
||||
code?: string;
|
||||
description?: string;
|
||||
active?: boolean;
|
||||
export interface DocumentTypeDigitizationListResponse {
|
||||
items: DocumentTypeDigitization[];
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
}
|
||||
|
||||
const BASE_URL = '/v1/a76/document-types-digitization';
|
||||
|
||||
/**
|
||||
* API para Tipos de Documentos de Digitalización
|
||||
* API de solo lectura para Tipos de Documentos de Digitalización
|
||||
*/
|
||||
export const documentTypesDigitizationApi = {
|
||||
/**
|
||||
* Obtener todos los tipos de documentos para digitalización
|
||||
*/
|
||||
getAll: (activeOnly: boolean = true) => {
|
||||
// CORRECTO: Al tener BASE_URL con slash, queda "...digitization/?active..."
|
||||
const url = `${BASE_URL}?active_only=${activeOnly}`;
|
||||
return api.get<DocumentTypeDigitization[]>(url);
|
||||
list: (
|
||||
page = 1,
|
||||
pageSize = 50,
|
||||
companyId: number,
|
||||
search?: string,
|
||||
activeOnly = false
|
||||
) => {
|
||||
const params = new URLSearchParams({
|
||||
page: page.toString(),
|
||||
page_size: pageSize.toString(),
|
||||
company_id: companyId.toString()
|
||||
});
|
||||
|
||||
if (search) {
|
||||
params.append('search', search);
|
||||
}
|
||||
|
||||
if (activeOnly) {
|
||||
params.append('active_only', 'true');
|
||||
}
|
||||
|
||||
return api.get<DocumentTypeDigitizationListResponse>(`${BASE_URL}/?${params.toString()}`);
|
||||
},
|
||||
|
||||
/**
|
||||
* Obtener un tipo de documento por ID
|
||||
*/
|
||||
getById: (id: number) => {
|
||||
// CORREGIDO: Añadido slash después del ID
|
||||
return api.get<DocumentTypeDigitization>(`${BASE_URL}${id}/`);
|
||||
getAll: (companyId: number, activeOnly = true, search?: string) => {
|
||||
return documentTypesDigitizationApi.list(1, 2000, companyId, search, activeOnly);
|
||||
},
|
||||
|
||||
/**
|
||||
* Obtener un tipo de documento por código
|
||||
*/
|
||||
getByCode: (code: string) => {
|
||||
// CORREGIDO: Añadido slash después del código
|
||||
return api.get<DocumentTypeDigitization>(`${BASE_URL}by-code/${code}/`);
|
||||
getById: (id: number, companyId: number) => {
|
||||
return api.get<DocumentTypeDigitization>(`${BASE_URL}/${id}/?company_id=${companyId}`);
|
||||
},
|
||||
|
||||
/**
|
||||
* Crear un nuevo tipo de documento
|
||||
*/
|
||||
create: (data: DocumentTypeDigitizationCreate) => {
|
||||
// CORRECTO: Usa la BASE_URL que ya termina en /
|
||||
return api.post<DocumentTypeDigitization>(BASE_URL, data);
|
||||
},
|
||||
|
||||
/**
|
||||
* Actualizar un tipo de documento existente
|
||||
*/
|
||||
update: (id: number, data: DocumentTypeDigitizationUpdate) => {
|
||||
// CORREGIDO: Añadido slash después del ID
|
||||
return api.put<DocumentTypeDigitization>(`${BASE_URL}${id}/`, data);
|
||||
},
|
||||
|
||||
/**
|
||||
* Eliminar (soft delete) un tipo de documento
|
||||
*/
|
||||
delete: (id: number) => {
|
||||
// CORREGIDO: Añadido slash después del ID
|
||||
return api.delete(`${BASE_URL}${id}/`);
|
||||
getByCode: (code: string, companyId: number) => {
|
||||
return api.get<DocumentTypeDigitization>(`${BASE_URL}/by-code/${code}/?company_id=${companyId}`);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user