feat: Implement API clients and UI components for managing units of measure and locations
- Added API client for OMA units of measure with CRUD operations. - Created API client for general unit measures with CRUD functionality. - Developed UI components for displaying and managing locations in a data table format. - Implemented data table actions for unit measures, including create, edit, and delete functionalities. - Integrated pagination and refresh capabilities in the data tables for both customs and general unit measures. - Enhanced user experience with dialogs for creating and editing units of measure. - Added server-side loading logic for fetching locations and units of measure with error handling.
This commit is contained in:
21
frontend/src/lib/api/dashboard/a76/general_catalogs/index.ts
Normal file
21
frontend/src/lib/api/dashboard/a76/general_catalogs/index.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Índice de exportación para catálogos generales A76
|
||||
*/
|
||||
|
||||
// Unit Measures - Main
|
||||
export * from './unit-measures';
|
||||
|
||||
// Unit Measures - Customs (Mexican)
|
||||
export * from './um-customs-mex';
|
||||
|
||||
// Unit Measures - American
|
||||
export * from './um-customs-ame';
|
||||
|
||||
// Unit Measures - ACE
|
||||
export * from './um-ace';
|
||||
|
||||
// Unit Measures - OMA
|
||||
export * from './um-oma';
|
||||
|
||||
// Locations (from ports)
|
||||
export * from './locations';
|
||||
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* API Client para Locations - Ubicaciones relacionadas con puertos
|
||||
* Basado en los campos location_code y location_description del módulo de puertos
|
||||
*/
|
||||
import { api } from '$lib/api';
|
||||
import type { ApiResponse } from '$lib/api';
|
||||
|
||||
export interface Location {
|
||||
location_code: string;
|
||||
location_description: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nota: Las ubicaciones están integradas en el módulo de puertos.
|
||||
* Este archivo proporciona tipos para trabajar con ubicaciones,
|
||||
* pero las operaciones se realizan a través del módulo de puertos.
|
||||
*
|
||||
* Ver: /a76/ports para operaciones relacionadas con ubicaciones
|
||||
*/
|
||||
|
||||
/**
|
||||
* Obtiene ubicaciones únicas de los puertos
|
||||
* Esta función extrae las ubicaciones únicas de la lista de puertos
|
||||
*/
|
||||
export async function getLocationsFromPorts(): Promise<ApiResponse<Location[]>> {
|
||||
const portsResponse = await api.get('/a76/ports?page_size=1000');
|
||||
|
||||
if (portsResponse.error || !portsResponse.data) {
|
||||
return {
|
||||
error: portsResponse.error || 'Error al obtener puertos',
|
||||
status: portsResponse.status
|
||||
};
|
||||
}
|
||||
|
||||
// Extraer ubicaciones únicas
|
||||
const locationMap = new Map<string, Location>();
|
||||
const ports = portsResponse.data.items || [];
|
||||
|
||||
ports.forEach((port: any) => {
|
||||
if (port.location_code && !locationMap.has(port.location_code)) {
|
||||
locationMap.set(port.location_code, {
|
||||
location_code: port.location_code,
|
||||
location_description: port.location_description
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
data: Array.from(locationMap.values()),
|
||||
status: 200
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* API Client para UM ACE - Unidades de medida ACE
|
||||
*/
|
||||
import { api } from '$lib/api';
|
||||
import type { ApiResponse } from '$lib/api';
|
||||
|
||||
export interface UMACE {
|
||||
id: number;
|
||||
code: string;
|
||||
description: string | null;
|
||||
created_at: string | null;
|
||||
updated_at: string | null;
|
||||
}
|
||||
|
||||
export interface UMACECreate {
|
||||
code: string;
|
||||
description?: string | null;
|
||||
}
|
||||
|
||||
export interface UMACEUpdate {
|
||||
code?: string;
|
||||
description?: string | null;
|
||||
}
|
||||
|
||||
export interface UMACEListResponse {
|
||||
items: UMACE[];
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
pages: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lista todas las unidades de medida ACE
|
||||
*/
|
||||
export async function getUMACE(
|
||||
page = 1,
|
||||
pageSize = 50,
|
||||
filters: Record<string, any> = {}
|
||||
): Promise<ApiResponse<UMACEListResponse>> {
|
||||
const queryParams = new URLSearchParams({
|
||||
page: page.toString(),
|
||||
page_size: pageSize.toString(),
|
||||
...filters
|
||||
});
|
||||
return await api.get(`/a76/units-of-measure/ace?${queryParams.toString()}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene una unidad de medida por ID
|
||||
*/
|
||||
export async function getUMACEById(id: number): Promise<ApiResponse<UMACE>> {
|
||||
return await api.get(`/a76/units-of-measure/ace/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea una nueva unidad de medida
|
||||
*/
|
||||
export async function createUMACE(data: UMACECreate): Promise<ApiResponse<UMACE>> {
|
||||
return await api.post('/a76/units-of-measure/ace', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Actualiza una unidad de medida
|
||||
*/
|
||||
export async function updateUMACE(id: number, data: UMACEUpdate): Promise<ApiResponse<UMACE>> {
|
||||
return await api.put(`/a76/units-of-measure/ace/${id}`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Elimina una unidad de medida
|
||||
*/
|
||||
export async function deleteUMACE(id: number): Promise<ApiResponse<void>> {
|
||||
return await api.delete(`/a76/units-of-measure/ace/${id}`);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* API Client para UM American - Unidades de medida americanas
|
||||
*/
|
||||
import { api } from '$lib/api';
|
||||
import type { ApiResponse } from '$lib/api';
|
||||
|
||||
export interface UMCustomsAme {
|
||||
id: number;
|
||||
code: string;
|
||||
description: string | null;
|
||||
created_at: string | null;
|
||||
updated_at: string | null;
|
||||
}
|
||||
|
||||
export interface UMCustomsAmeCreate {
|
||||
code: string;
|
||||
description?: string | null;
|
||||
}
|
||||
|
||||
export interface UMCustomsAmeUpdate {
|
||||
code?: string;
|
||||
description?: string | null;
|
||||
}
|
||||
|
||||
export interface UMCustomsAmeListResponse {
|
||||
items: UMCustomsAme[];
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
pages: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lista todas las unidades de medida americanas
|
||||
*/
|
||||
export async function getUMCustomsAme(
|
||||
page = 1,
|
||||
pageSize = 50,
|
||||
filters: Record<string, any> = {}
|
||||
): Promise<ApiResponse<UMCustomsAmeListResponse>> {
|
||||
const queryParams = new URLSearchParams({
|
||||
page: page.toString(),
|
||||
page_size: pageSize.toString(),
|
||||
...filters
|
||||
});
|
||||
return await api.get(`/a76/units-of-measure/american?${queryParams.toString()}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene una unidad de medida por ID
|
||||
*/
|
||||
export async function getUMCustomsAmeById(id: number): Promise<ApiResponse<UMCustomsAme>> {
|
||||
return await api.get(`/a76/units-of-measure/american/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea una nueva unidad de medida
|
||||
*/
|
||||
export async function createUMCustomsAme(data: UMCustomsAmeCreate): Promise<ApiResponse<UMCustomsAme>> {
|
||||
return await api.post('/a76/units-of-measure/american', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Actualiza una unidad de medida
|
||||
*/
|
||||
export async function updateUMCustomsAme(id: number, data: UMCustomsAmeUpdate): Promise<ApiResponse<UMCustomsAme>> {
|
||||
return await api.put(`/a76/units-of-measure/american/${id}`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Elimina una unidad de medida
|
||||
*/
|
||||
export async function deleteUMCustomsAme(id: number): Promise<ApiResponse<void>> {
|
||||
return await api.delete(`/a76/units-of-measure/american/${id}`);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* API Client para UM Customs (Mexican) - Unidades de medida para aduanas mexicanas
|
||||
*/
|
||||
import { api } from '$lib/api';
|
||||
import type { ApiResponse } from '$lib/api';
|
||||
|
||||
export interface UMCustomsMex {
|
||||
id: number;
|
||||
code: string;
|
||||
description: string | null;
|
||||
created_at: string | null;
|
||||
updated_at: string | null;
|
||||
}
|
||||
|
||||
export interface UMCustomsMexCreate {
|
||||
code: string;
|
||||
description?: string | null;
|
||||
}
|
||||
|
||||
export interface UMCustomsMexUpdate {
|
||||
code?: string;
|
||||
description?: string | null;
|
||||
}
|
||||
|
||||
export interface UMCustomsMexListResponse {
|
||||
items: UMCustomsMex[];
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
pages: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lista todas las unidades de medida para aduanas mexicanas
|
||||
*/
|
||||
export async function getUMCustomsMex(
|
||||
page = 1,
|
||||
pageSize = 50,
|
||||
filters: Record<string, any> = {}
|
||||
): Promise<ApiResponse<UMCustomsMexListResponse>> {
|
||||
const queryParams = new URLSearchParams({
|
||||
page: page.toString(),
|
||||
page_size: pageSize.toString(),
|
||||
...filters
|
||||
});
|
||||
return await api.get(`/a76/units-of-measure/customs?${queryParams.toString()}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene una unidad de medida por ID
|
||||
*/
|
||||
export async function getUMCustomsMexById(id: number): Promise<ApiResponse<UMCustomsMex>> {
|
||||
return await api.get(`/a76/units-of-measure/customs/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea una nueva unidad de medida
|
||||
*/
|
||||
export async function createUMCustomsMex(data: UMCustomsMexCreate): Promise<ApiResponse<UMCustomsMex>> {
|
||||
return await api.post('/a76/units-of-measure/customs', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Actualiza una unidad de medida
|
||||
*/
|
||||
export async function updateUMCustomsMex(id: number, data: UMCustomsMexUpdate): Promise<ApiResponse<UMCustomsMex>> {
|
||||
return await api.put(`/a76/units-of-measure/customs/${id}`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Elimina una unidad de medida
|
||||
*/
|
||||
export async function deleteUMCustomsMex(id: number): Promise<ApiResponse<void>> {
|
||||
return await api.delete(`/a76/units-of-measure/customs/${id}`);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* API Client para UM OMA - Unidades de medida OMA
|
||||
*/
|
||||
import { api } from '$lib/api';
|
||||
import type { ApiResponse } from '$lib/api';
|
||||
|
||||
export interface UMOMA {
|
||||
id: number;
|
||||
code: string;
|
||||
description: string | null;
|
||||
created_at: string | null;
|
||||
updated_at: string | null;
|
||||
}
|
||||
|
||||
export interface UMOMACreate {
|
||||
code: string;
|
||||
description?: string | null;
|
||||
}
|
||||
|
||||
export interface UMOMAUpdate {
|
||||
code?: string;
|
||||
description?: string | null;
|
||||
}
|
||||
|
||||
export interface UMOMAListResponse {
|
||||
items: UMOMA[];
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
pages: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lista todas las unidades de medida OMA
|
||||
*/
|
||||
export async function getUMOMA(
|
||||
page = 1,
|
||||
pageSize = 50,
|
||||
filters: Record<string, any> = {}
|
||||
): Promise<ApiResponse<UMOMAListResponse>> {
|
||||
const queryParams = new URLSearchParams({
|
||||
page: page.toString(),
|
||||
page_size: pageSize.toString(),
|
||||
...filters
|
||||
});
|
||||
return await api.get(`/a76/units-of-measure/oma?${queryParams.toString()}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene una unidad de medida por ID
|
||||
*/
|
||||
export async function getUMOMAById(id: number): Promise<ApiResponse<UMOMA>> {
|
||||
return await api.get(`/a76/units-of-measure/oma/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea una nueva unidad de medida
|
||||
*/
|
||||
export async function createUMOMA(data: UMOMACreate): Promise<ApiResponse<UMOMA>> {
|
||||
return await api.post('/a76/units-of-measure/oma', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Actualiza una unidad de medida
|
||||
*/
|
||||
export async function updateUMOMA(id: number, data: UMOMAUpdate): Promise<ApiResponse<UMOMA>> {
|
||||
return await api.put(`/a76/units-of-measure/oma/${id}`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Elimina una unidad de medida
|
||||
*/
|
||||
export async function deleteUMOMA(id: number): Promise<ApiResponse<void>> {
|
||||
return await api.delete(`/a76/units-of-measure/oma/${id}`);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* API Client para Unit Measures - Catálogo principal de unidades de medida
|
||||
*/
|
||||
import { api } from '$lib/api';
|
||||
import type { ApiResponse } from '$lib/api';
|
||||
|
||||
export interface UnitMeasure {
|
||||
id: number;
|
||||
code: string;
|
||||
description: string | null;
|
||||
created_at: string | null;
|
||||
updated_at: string | null;
|
||||
}
|
||||
|
||||
export interface UnitMeasureCreate {
|
||||
code: string;
|
||||
description?: string | null;
|
||||
}
|
||||
|
||||
export interface UnitMeasureUpdate {
|
||||
code?: string;
|
||||
description?: string | null;
|
||||
}
|
||||
|
||||
export interface UnitMeasureListResponse {
|
||||
items: UnitMeasure[];
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
pages: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lista todas las unidades de medida
|
||||
*/
|
||||
export async function getUnitMeasures(
|
||||
page = 1,
|
||||
pageSize = 50,
|
||||
filters: Record<string, any> = {}
|
||||
): Promise<ApiResponse<UnitMeasureListResponse>> {
|
||||
const queryParams = new URLSearchParams({
|
||||
page: page.toString(),
|
||||
page_size: pageSize.toString(),
|
||||
...filters
|
||||
});
|
||||
return await api.get(`/a76/units-of-measure?${queryParams.toString()}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene una unidad de medida por ID
|
||||
*/
|
||||
export async function getUnitMeasure(id: number): Promise<ApiResponse<UnitMeasure>> {
|
||||
return await api.get(`/a76/units-of-measure/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea una nueva unidad de medida
|
||||
*/
|
||||
export async function createUnitMeasure(data: UnitMeasureCreate): Promise<ApiResponse<UnitMeasure>> {
|
||||
return await api.post('/a76/units-of-measure', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Actualiza una unidad de medida
|
||||
*/
|
||||
export async function updateUnitMeasure(id: number, data: UnitMeasureUpdate): Promise<ApiResponse<UnitMeasure>> {
|
||||
return await api.put(`/a76/units-of-measure/${id}`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Elimina una unidad de medida
|
||||
*/
|
||||
export async function deleteUnitMeasure(id: number): Promise<ApiResponse<void>> {
|
||||
return await api.delete(`/a76/units-of-measure/${id}`);
|
||||
}
|
||||
Reference in New Issue
Block a user