82 lines
2.4 KiB
TypeScript
82 lines
2.4 KiB
TypeScript
/**
|
|
* API Client para Incoterms
|
|
* Gestiona las operaciones CRUD para los términos internacionales de comercio
|
|
*/
|
|
import { api } from '$lib/api';
|
|
|
|
export interface Incoterm {
|
|
code: string;
|
|
description_es: string;
|
|
description_en: string;
|
|
}
|
|
|
|
export interface IncotermListResponse {
|
|
items: Incoterm[];
|
|
total: number;
|
|
page: number;
|
|
page_size: number;
|
|
}
|
|
|
|
export interface CreateIncotermData {
|
|
code: string;
|
|
description_es: string;
|
|
description_en: string;
|
|
}
|
|
|
|
export interface UpdateIncotermData {
|
|
code?: string;
|
|
description_es?: string;
|
|
description_en?: string;
|
|
}
|
|
|
|
/**
|
|
* API para Incoterms
|
|
*/
|
|
export const incotermsApi = {
|
|
/**
|
|
* Lista todos los incoterms con paginación y filtros
|
|
* @param page - Número de página (por defecto 1)
|
|
* @param pageSize - Tamaño de página (por defecto 50)
|
|
* @param code - Filtrar por clave (opcional)
|
|
* @param description - Filtrar por descripción (opcional)
|
|
*/
|
|
list: (page = 1, pageSize = 50, code?: string, description?: string) => {
|
|
let url = `/v1/public/reference_data/incoterms/?page=${page}&page_size=${pageSize}`;
|
|
if (code) url += `&code=${encodeURIComponent(code)}`;
|
|
if (description) url += `&description=${encodeURIComponent(description)}`;
|
|
return api.get<IncotermListResponse>(url);
|
|
},
|
|
|
|
/**
|
|
* Obtiene un incoterm por código
|
|
* @param code - Código del incoterm
|
|
*/
|
|
get: (code: string) =>
|
|
// CORREGIDO: Añadido '/' final
|
|
api.get<Incoterm>(`/v1/public/reference_data/incoterms/${code}/`),
|
|
|
|
/**
|
|
* Crea un nuevo incoterm
|
|
* @param data - Datos del incoterm a crear
|
|
*/
|
|
create: (data: CreateIncotermData) =>
|
|
// CORREGIDO: Añadido '/' final
|
|
api.post<Incoterm>('/v1/public/reference_data/incoterms/', data),
|
|
|
|
/**
|
|
* Actualiza un incoterm existente
|
|
* @param code - Código del incoterm a actualizar
|
|
* @param data - Datos a actualizar
|
|
*/
|
|
update: (code: string, data: UpdateIncotermData) =>
|
|
// CORREGIDO: Añadido '/' final después del código
|
|
api.put<Incoterm>(`/v1/public/reference_data/incoterms/${code}/`, data),
|
|
|
|
/**
|
|
* Elimina un incoterm
|
|
* @param code - Código del incoterm a eliminar
|
|
*/
|
|
delete: (code: string) =>
|
|
// CORREGIDO: Añadido '/' final después del código
|
|
api.delete(`/v1/public/reference_data/incoterms/${code}/`)
|
|
}; |