96 lines
2.1 KiB
TypeScript
96 lines
2.1 KiB
TypeScript
/**
|
|
* API client for Countries operations
|
|
*/
|
|
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 CountryCreateRequest {
|
|
m3_key: string;
|
|
mex_key: string;
|
|
ame_key: string;
|
|
description_es: string;
|
|
description_en: string;
|
|
}
|
|
|
|
export interface CountryUpdateRequest {
|
|
m3_key: string;
|
|
mex_key: string;
|
|
ame_key: string;
|
|
description_es: string;
|
|
description_en: string;
|
|
}
|
|
|
|
/**
|
|
* Get all countries with pagination
|
|
*/
|
|
export async function getCountries(
|
|
filters?: {
|
|
page?: number;
|
|
page_size?: number;
|
|
}
|
|
): Promise<{ data: CountryListResponse; status: number }> {
|
|
const params = new URLSearchParams();
|
|
|
|
if (filters?.page) params.append('page', filters.page.toString());
|
|
if (filters?.page_size) params.append('page_size', filters.page_size.toString());
|
|
|
|
const response = await api.get(`/v1/public/refrence_data/countries?${params.toString()}`);
|
|
|
|
return response;
|
|
}
|
|
|
|
/**
|
|
* Get a single country by m3_key
|
|
*/
|
|
export async function getCountry(
|
|
m3_key: string
|
|
): Promise<{ data: Country; status: number }> {
|
|
const response = await api.get(`/v1/public/refrence_data/countries/${m3_key}`);
|
|
return response;
|
|
}
|
|
|
|
/**
|
|
* Create a new country
|
|
*/
|
|
export async function createCountry(
|
|
data: CountryCreateRequest
|
|
): Promise<{ data: Country; status: number }> {
|
|
const response = await api.post(`/v1/public/refrence_data/countries`, data);
|
|
return response;
|
|
}
|
|
|
|
/**
|
|
* Update an existing country
|
|
*/
|
|
export async function updateCountry(
|
|
m3_key: string,
|
|
data: CountryUpdateRequest
|
|
): Promise<{ data: Country; status: number }> {
|
|
const response = await api.put(`/v1/public/refrence_data/countries/${m3_key}`, data);
|
|
return response;
|
|
}
|
|
|
|
/**
|
|
* Delete a country
|
|
*/
|
|
export async function deleteCountry(
|
|
m3_key: string
|
|
): Promise<{ data: any; status: number }> {
|
|
const response = await api.delete(`/v1/public/refrence_data/countries/${m3_key}`);
|
|
return response;
|
|
}
|