- Added a trailing slash to the GET, POST, PUT, and DELETE requests for incoterms, invoice types, material types, payment methods, pedimento codes, pedimento regimens, sectors, states, transport modes, transport types, and valuation methods APIs. - Ensured that the pagination endpoints include a leading slash before query parameters.
85 lines
2.2 KiB
TypeScript
85 lines
2.2 KiB
TypeScript
/**
|
|
* API Client para Countries
|
|
* Gestiona las operaciones CRUD para los países
|
|
*/
|
|
import { api } from '$lib/api';
|
|
|
|
export interface Country {
|
|
m3_key: string;
|
|
mex_key: string;
|
|
ame_key: string;
|
|
description_es: string;
|
|
description_en: string;
|
|
}
|
|
|
|
export interface CountryListResponse {
|
|
items: Country[];
|
|
total: number;
|
|
page: number;
|
|
page_size: number;
|
|
}
|
|
|
|
export interface CreateCountryData {
|
|
m3_key: string;
|
|
mex_key: string;
|
|
ame_key: string;
|
|
description_es: string;
|
|
description_en: string;
|
|
}
|
|
|
|
export interface UpdateCountryData {
|
|
m3_key?: string;
|
|
mex_key?: string;
|
|
ame_key?: string;
|
|
description_es?: string;
|
|
description_en?: string;
|
|
}
|
|
|
|
/**
|
|
* API para Countries
|
|
*/
|
|
export const countriesApi = {
|
|
/**
|
|
* Lista todos los países con paginación
|
|
* @param page - Número de página (por defecto 1)
|
|
* @param pageSize - Tamaño de página (por defecto 50)
|
|
*/
|
|
list: (page = 1, pageSize = 50) =>
|
|
api.get<CountryListResponse>(
|
|
// CORREGIDO: Añadido '/' antes del '?'
|
|
`/v1/public/refrence_data/countries/?page=${page}&page_size=${pageSize}`
|
|
),
|
|
|
|
/**
|
|
* Obtiene un país por su clave M3
|
|
* @param m3_key - Clave M3 del país
|
|
*/
|
|
get: (m3_key: string) =>
|
|
// CORREGIDO: Añadido '/' al final
|
|
api.get<Country>(`/v1/public/refrence_data/countries/${m3_key}/`),
|
|
|
|
/**
|
|
* Crea un nuevo país
|
|
* @param data - Datos del país a crear
|
|
*/
|
|
create: (data: CreateCountryData) =>
|
|
// CORREGIDO: Añadido '/' al final
|
|
api.post<Country>('/v1/public/refrence_data/countries/', data),
|
|
|
|
/**
|
|
* Actualiza un país existente
|
|
* @param m3_key - Clave M3 del país a actualizar
|
|
* @param data - Datos a actualizar
|
|
*/
|
|
update: (m3_key: string, data: UpdateCountryData) =>
|
|
// CORREGIDO: Añadido '/' después de la clave
|
|
api.put<Country>(`/v1/public/refrence_data/countries/${m3_key}/`, data),
|
|
|
|
/**
|
|
* Elimina un país
|
|
* @param m3_key - Clave M3 del país a eliminar
|
|
*/
|
|
delete: (m3_key: string) =>
|
|
// CORREGIDO: Añadido '/' después de la clave
|
|
api.delete(`/v1/public/refrence_data/countries/${m3_key}/`)
|
|
}; |